.htaccess Rewrite changes the Anchor tag or hash (#) to %23 in the destination URL

  • htaccess
  • >
  • .htaccess Rewrite changes the Anchor tag or hash (#) to %23 in the destination URL

.htaccess Rewrite changes the Anchor tag or hash (#) to %23 in the destination URL

[vc_row type=”in_container” full_screen_row_position=”middle” scene_position=”center” text_color=”dark” text_align=”left” overlay_strength=”0.3″][vc_column column_padding=”no-extra-padding” column_padding_position=”all” background_color_opacity=”1″ background_hover_color_opacity=”1″ column_shadow=”none” width=”1/1″ tablet_text_alignment=”default” phone_text_alignment=”default” column_border_width=”none” column_border_style=”solid”][vc_column_text]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:

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

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.

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

The resulting URL will be:

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

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

[/vc_column_text][/vc_column][/vc_row]

2 Responses

Leave a Reply

Schedule a Virtual Meeting To Find The Best Plans For You

Let’s have a chat about how we can help you improve your business, reach more customers online, generate more leads and make more sales.

Our services are tailored and customized specifically for you; guaranteeing the best results possible.