I'm trying top redirect a standard Wordpress "folder" URL of a page to a new one on the same domain while keeping all subfolders, query strings etc. From
RedirectMatch 301 ^/old-path(.*) /new-path$1
...this being WP, another redirect happens from
/new-path is a physical directory then it's not WP that is triggering the redirect, it is Apache's mod_dir that is "fixing" the URL.
However, since you are using WordPress, it is preferable to use mod_rewrite (
RewriteRule) to perform the redirect instead of a mod_alias
RedirectMatch in order to avoid conflicts. Different modules execute at different times during the request and WP already uses mod_rewrite.
Try something like the following at the top of your
.htaccess file before any existing WP directives:
RewriteRule ^dir/?(.*) /new-dir/$1 [R,L]
As you can see, although the slash is optional in the
RewriteRule pattern, this is never captured by the regex and the slash is always present in the substitution.
R (temporary) redirect to a
R=301 only when you are sure it's working OK.