I need to add some rewrite rules on my posts in order to have one or more urls for the same post. E.g /foo/post-name
and bar/post-name
should lead the same post. I'm using this function:
function addRewritePost() {
add_rewrite_rule( '^foo/([^/]+)/?', 'index.php?name=$matches[1]', 'top' );
add_rewrite_rule( '^bar/([^/]+)/?', 'index.php?name=$matches[1]', 'top' );
}
add_action('init','addRewritePost');
This code redirects from foo/post-name
to /post-name
and I don't want this kind of behaivor.
How can I solve this issue?