Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache rewrite rule for a destination containing a hash mark

Tags:

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 ?

like image 331
ascobol Avatar asked Apr 03 '12 12:04

ascobol


People also ask

What is RewriteRule * F?

RewriteRule "\.exe" "-" [F] This example uses the "-" syntax for the rewrite target, which means that the requested URI is not modified. There's no reason to rewrite to another URI, if you're going to forbid the request.

What is $1 rewrite rule?

In your rewrite, the ^ signifies the start of the string, the (. *) says to match anything, and the $ signifies the end of the string. So, basically, it's saying grab everything from the start to the end of the string and assign that value to $1.

What is Apache rewrite rule?

A rewrite rule can be invoked in httpd. conf or in . htaccess . The path generated by a rewrite rule can include a query string, or can lead to internal sub-processing, external request redirection, or internal proxy throughput.

What is QSA in htaccess?

QSA means that if there's a query string passed with the original URL, it will be appended to the rewrite ( olle? p=1 will be rewritten as index.


1 Answers

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.

like image 187
ascobol Avatar answered Sep 21 '22 18:09

ascobol