Forum Moderators: phranque
i have written a rewrite rule to redirect into a PHP page.
RewriteRule ^Details/([0-9]+)/([a-zA-Z0-9-,]+)$ category\.php?cat=$1&perma=$2 [L]
it was working like
when i call
example.com/Details/2/Commercial
then it redirects to
example.com/category.php?cat=2&perma=Commercial
with my old hosting
but the same code is not working in my new hosting
the other rules are working as normally in the new hosting
for eg.:
RewriteRule ^full_details$ all_category\.php [L]
Prev. Apache version2.2.9 (Unix)
Present Apache/1.3.37
Please help
Thanks in Advance
Regards
Anees
A more robust solution is to escape the "-" character by preceding it with a "\" whenever it is used in a character-group. This allows you to put the hyphen in any position within the group, so that characters can be ordered from most-likely-to-occur to least-likely-to-occur for the sake of efficiency.
Note that the escaping rules inside alternate-character groups are more relaxed than outside alternate-character groups. With a character group, only "^", "-", and "]" need to be escaped. Outside alternate-character groups, the following characters must be escaped in mod_rewrite regex patterns if you wish to match them as literals, rather than use them as regex pattern tokens or operators:
"^", "$", "%", "?", "*", "+", "(", ")", "[", "]", "{", "}", "¦", "\", ".", in all cases, and ' " ', ">", "<" or "=" if used as the initial character of the pattern.
Jim
This is what apparently does happen on Apache 2.x, but it seems that the older 1.3 version got confused and tried to treat it as another range declaration overlapping with the 0-9 range; It thought you were trying to define two ranges, both "0"-to-"9" and "9"-to-"," and it got confused.
Using [a-zA-Z0-9\-,] with the third hyphen escaped by the preceding "\" is a safe and robust solution that will work an any server and any version of the POSIX regular-expressions library (which is actually part of the operating system, not the server).
Jim