Apache RedirectMatch with Regex Apache RedirectMatch with Regex apache apache

Apache RedirectMatch with Regex


You can just use this rule in your site root .htaccess:

RewriteEngine OnRewriteRule ^/?(path)/(.+)$ /$1/#/$2 [L,NE,NC,R=301]

It will redirect /path/test/test to /path/#test/test.

There is no need to check for presence of # in RewriteRule because client browsers don't send any part after # to web server anyway.


You can try this:

RedirectMatch ^/path/([^#]+)$ /path/#/$1

The captured group ([^#]+) represents any string, minimum 1 character, that doesn't contain #.