Apache rewrite rule for a destination containing a hash mark

ascobol picture ascobol · Apr 3, 2012 · Viewed 20.6k times · Source

I'm trying to issue a redirect where the destination contains a fragment-identifier part. I tried with this rule:

RewriteRule   ^/foo/bar/([^/]+)/(.*)$  /cgi/script#foobar::$1.$2  [R,L]

However the # is converted into %23 and the web application cannot correctly parse this url. How can I force apache to keep the # character ?

Answer

ascobol picture ascobol · Apr 3, 2012

Solution found: there is an option for not escaping urls with mod_rewrite:

https://httpd.apache.org/docs/2.2/rewrite/flags.html#flag_ne

Adding the [NE] flag solved the problem.