Lost in RewriteRule translation
This is the first time I came across this thing, and I've been working with Apache for about 13 years now.
I have this rewrite rule:
RewriteRule ^/tagged/(.*)/$ /index.php?a=tagged&tags=$1
Very simple, right? Here is the deal: if the value of the "tag" contains urlencoded chars - they are just lost in translation. Gone, bye-bye!?
If I enter url like this: /tagged/c%2B%2B/ which is the wight way to urlencode c++ then ind开发者_JAVA百科ex.php receives the value of tags=c where did my ++ go?
When I enter c%2B%2B directly in the url like this: /index.php?a=tagged&tags=c%2B%2B then everything if fine, happily finding my posts tagged c++
Is this a known issue? What's the workaround?
I had a problem very similar to this once. Here is the link I used to solve it. The issue is that, as the link suggests, by the time mod_rewrite performs its rules Apache has already unescaped the URL and so when you rewrite the URL to the PHP script, PHP will interpret the +'s as spaces.
Edit: the post has been updated:
Update 24th August 2009: Apache 2.2.12 includes a B flag to RewriteRule that is meant to be used for this issue. It was introduced in 2.2.7, but broken until 2.2.12, if I read the changelog correctly. Thanks to Michael Stillwell for letting me know.
Did you try to use
RewriteRule ^/tagged/(.*)/$ /index.php?a=tagged&tags=$1 [NE]
NE stands for NoEscape. Never used it so don't know if it just don't escape character that are not already urlencoded, or just write non urlencoded characters and convert those which were.
精彩评论