Apache Rewrite Rule Flags – NE


I was working on an Apache URL redirection request this morning. The task is to redirect the URL ‘^/example/1’ to ‘/#example1’. My first configuration is something like below. When I test it, the redirected URL becomes …/%23example1 instead of …/#example1.

RewriteRule ^/example/1(/)?$ %{HTTP_HOST}/#example1 [R,L,NC]

As you see the problem is that the redirection automatically convert the special character (#) to hexicode (%23). To avoid the conversion, the flag NE has to be applied to the rewrite rule.

RewriteRule ^/example/1(/)?$ %{HTTP_HOST}/#example1 [R,L,NC,NE]

BTW, curl is a better testing tool than browser due to the the history may be cached in the browser. Check the Location value in the output of this comand curl –I –L http://…/example/1

Reference:

http://www.ascii.cl/htmlcodes.htm
https://httpd.apache.org/docs/2.2/rewrite/flags.html#flag_ne

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s