问题
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.
回答1:
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
回答2:
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.
来源:https://stackoverflow.com/questions/8822650/encoding-special-characters-in-url-rewriting-using-htaccess