Recently, while working on my project (a
site with articles on how to do ), I encountered a problem with mod_rewrite. The essence of the problem was the following: in the tag cloud, when switching to the “C ++” tag (processed by urlencode and becoming C% 2B% 2B) I got to the “C” tag (the letter “C” and 2 spaces).
The rule in .htaccess was:
RewriteRule ^ tag / ([^ /] +) / $ index.php? Tag = $ 1 [L]
Through experiments, I found out that the $ 1 rule does not fall into “C% 2B% 2B”, but “C ++” (inside Apache% 2B turns into +). Plus, of course, was regarded as a space connecting two words.
')
I dug up the Internet for a long time in search of a solution, experimented with flags, until on request in Google “C ++ mod_rewrite” I found a post describing this bug of Apache somewhere on the forums on apache.org (as I understand from this post - my problem is a bug Apache).
In this post, the author advised to disassemble regular% {THE_REQUEST}, in which "C% 2B% 2B" was in its original form and not replaced with "C ++". % {THE_REQUEST} usually contains something like "GET tag / C% 2B% 2B / HTTP 1.1".
Reception helped, I redid the old rewrite rule for this:
RewriteCond% {THE_REQUEST} ^ GET [\] + / tag / ([^ /] +) / [\] + HTTP. * $
RewriteRule ^ (. *) $ Index.php? Tag =% 1 [L]
Tested on versions of Apache 2.2 (Windows) and 1.3.4 (Linux).
Now users of my site can easily read articles tagged with "C ++" :)
I hope my post will help someone with a similar problem.