How to escape pound sign in Apache RewriteRule

Dock over water with LED sign that reads "Sweet Escape".
It's a feature, not a bug. But mostly a bug.

If you’re setting up a redirect and want to redirect to a specific page and “tab” on that page, you need to make sure Apache does not escape the URL, otherwise # will turn into %23. You can do that by using the NE (no escape) flag:

 RewriteRule ^/(.*) [R=301,NE,L]

That said, it’s probably not a good idea to use $1 anywhere in your URL, because that would allow a user to supply anything they want and Apache wouldn’t escape that either.

Featured image by Let's Go Together.