I am setting a WP that it should redirect all the request made to sub-directory to file inside that directory.
For example if there a visit on example.com/link/me
then it should send the user to /link/index.php?me
To achieve this, I am trying to add rewrite rule in theme function file. Here's what my code looks like:
function moin_add_rewrite_rules() {
add_rewrite_rule(
'^([^/]*)/(link)/(?:[a-z][a-z0-9_]*)?$',
'/link/index.php?$matches[1]',
'top'
);
}
add_action( 'init', 'moin_add_rewrite_rules' );
It is not working, visiting example.com/link/me
shows a 404 (as link is outside WP).
Is there any problem with regex code? or anywhere else? What could be other possible solution?