Updated November 02, 2017

You may want to use a # (Anchor tag or hash) within the destination URL you are rewriting or redirecting to and find that the resulting URL contains %23tag instead of #tag. Lets take a look at an example:

RewriteCond %{REQUEST_URI} /sample\.php$
RewriteCond %{QUERY_STRING} ^id=1$
RewriteRule .* https://example.com/sample/#tag [R=301,L]

The resulting URL in the browser will be :

https://example.com/sample/%23tag

You can simply use the NE flag (noescape). Using this flag will prevent the special characters from being converted to their hexcode equivalent.

RewriteCond %{REQUEST_URI} /sample\.php$
RewriteCond %{QUERY_STRING} ^id=1$
RewriteRule .* https://example.com/sample/#tag [R=301,NE,L]

The resulting URL will be:

https://example.com/sample/#tag

That’s it, you can now use # in the destination URL

Robert Rooke

Author Robert Rooke

More posts by Robert Rooke

Join the discussion One Comment

Leave a Reply