1

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.

2 Answers 2

3

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 
Sign up to request clarification or add additional context in comments.

1 Comment

Special character can also be written in the notation \x29.
0

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.

2 Comments

Thanks for your answer,but problem has not solved.%29 was just for example.I want to encode hebrew characters in this way.Can you tell why how to use %encoded character in .htaccess for url rewriting.
I don' quite understand what exactly you are attempting to do. However, you can try to escape the backreferences using the [B] flag (provided you use Apache >= 2.2, I believe), or play around with the noescape flag [NE]. More information can be found here: httpd.apache.org/docs/trunk/rewrite/flags.html.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.