Zerium
Zerium

Reputation: 17333

How to escape hash (#) characters in .htaccess?

I have something like the following in .htaccess:

RewriteRule ^a/(.+)$ index.php?data=$1 [L]

Simple enough, and works for most cases, except when I use the following URL:

http://example.com/a/hello%23abc

I expect this to set the data GET variable to hello#abc, but instead it breaks. I assume that it breaks because Apache "unescapes" the characters, making the url the following:

index.php?data=hello#abc

Which is probably why it's setting the data GET variable to hello.

Is there any way I can fix this?

Thanks.

Upvotes: 2

Views: 883

Answers (1)

RomanPerekhrest
RomanPerekhrest

Reputation: 92854

Using the [B] flag should help in your case(available in Apache 2.2)

The [B] flag instructs RewriteRule to escape non-alphanumeric characters before applying the transformation.

RewriteRule ^a/(.+)$ index.php?data=$1 [L,B]

http://httpd.apache.org/docs/2.2/rewrite/flags.html#flag_b

Upvotes: 3

Related Questions