think123 think123 - 1 year ago 126
PHP Question

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

I have something like the following in


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

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

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


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

Is there any way I can fix this?


Answer Source

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]

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download