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.