I need to take standard incoming urls and rewrite redirect them to target specific anchors on a single page (incoming html page name becomes the anchor name). E.g., the rule would be like this:
RewriteRule ^files/([a-zA-Z0-9\-_]+)\.html$ /test.html#$1 [R]
So this url:
http://foo.com/files/bar.html
...would become:
http://foo.com/test.html#bar
The rule itself works fine, but the # character gets encoded in the browser address bar to:
http://foo.com/test.html%23bar
which of course does not work correctly as an anchor. Is there a way in .htaccess to force it not to encode the hash? I also tried escaping it like \#
but that makes no difference.
Try the noescape (NE) flag in your rule:
RewriteRule ^files/([a-zA-Z0-9\-_]+)\.html$ /test.html#$1 [NE, R]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With