Default Pattern for Apache Mod_Rewrite

Found a bug? Tell us!!
Post Reply
johncanary
Regular
Posts: 116
Joined: Mon Aug 20, 2007 4:00 am
Location: Spain
Contact:

Default Pattern for Apache Mod_Rewrite

Post by johncanary »

After sweating for some time I finally figured out why
URL rewriting does not work as it theoretically should
in my setup.

You are using "-" as literal character in many default patterns
for the Mod_Rewrite RewriteRules for Apache.


However, that syntax to escape "-" has been introduced with
Regular Expressions Version 8

(according to PERL documentation, the mother for pattern
matching syntax.)

It seems that older versions of Apache don't use Version 8 for
pattern matching, meaning the "-" introduces a range. There might
be a dependence on Locale settings too. (don't know. It doesn't matter.)

All you need to do in order to achieve full backward compatibility is
to use the "older" syntax for that case.


Meaning, putting the "-" in the first or last position of the character
classes. Code readability does not suffer from that change.

I know you guys are very concerned about maintaining backward
compatibility.
That change can be done in a couple of minutes.

Code: Select all

Please, replace all instances of:

[0-9a-z\.\_!;,\-\%\+]

in the mod_rewrite / .htaccess default settings with:


[-0-9a-z\.\_!;,\%\+] or [0-9a-z\.\_!;,\%\+-]
Works like a charm.
I'd appreciate it very much.

This drove me crazy, since I have the latest Apache server
on my development machine at home, but still a 1.3 at
one of my webhosts. Couldn't figure out what's going on for a while
Hope it pays off for everyone else having troubles.
Yours John
: John's Google+ Profile
: John's E-Biz Booster Blog powered by Serendipity 1.7/PHP 5.3.14
johncanary
Regular
Posts: 116
Joined: Mon Aug 20, 2007 4:00 am
Location: Spain
Contact:

Re: Default Pattern for Apache Mod_Rewrite

Post by johncanary »

Nice quotes:

``The great thing about mod_rewrite is it gives you all the configurability and flexibility of Sendmail. The downside to mod_rewrite is that it gives you all the configurability and flexibility of Sendmail.''
-- Brian Behlendorf
Apache Group

`` Despite the tons of examples and docs, mod_rewrite is voodoo. Damned cool voodoo, but still voodoo. ''
-- Brian Moore
bem@news.cmc.net
Yours John
: John's Google+ Profile
: John's E-Biz Booster Blog powered by Serendipity 1.7/PHP 5.3.14
Post Reply