sunil
sunil

Reputation: 315

Encoding special characters in url rewriting using htaccess

I have a rewrite rule as following,it is working:

RewriteRule area/(.*) listing.php?area=$1

But when I want to use %29 in it,but when I rewrite it as following, I get 404 error:

RewriteRule area/something%29/(.*)/ listing.php?area=$1 

Escaping %29 as \%29 also not works.

Upvotes: 1

Views: 2084

Answers (2)

Gerben
Gerben

Reputation: 16825

Apache %-decodes the url-path before trying to apply the rewrite rules. So you should not use %-encoding in your RewriteRule. Just use the normal character.

So in your case you should just use the ). ) however is a special character in regular expression, so you should escape those in the RegEx way by adding a slash in front. So it will become \).

Your rule above should become:

RewriteRule area/something\)/(.*)/ listing.php?area=$1 

Upvotes: 3

Olaf
Olaf

Reputation: 10247

The URL you want to rewrite is invalid as %29 would only be allowed in a Querystring, not a URL. You need to escape the % as %25 (and not with a backslash), so the resulting expression would be ...something%2529 - which should work.

For more in depth information check RFC2396.

Upvotes: 0

Related Questions