PDA

View Full Version : Mod Rewrite


phppete
07-01-2007, 04:05 PM
How come this works fine on Apache 2


RewriteRule ^category/([\d]+)-([a-z0-9]+)/ category.php?id=$1 [QSA,L,NC]


but not on FQ, I finally tracked down that ^category/([\d]+) had to be changed to ^category/([0-9]+)

Is this a difference in Apache 1.3x and Apache 2 or something specific to FQ?

kitchin
07-01-2007, 09:44 PM
Apache 1.3 uses Extended Regular Expressions (egrep), and Apache 2 uses Perl Regular Expressions (PCRE).
http://httpd.apache.org/docs/2.0/new_features_2_0.html

If it's the full egrep then
[:digit:] would work like \d. But 0-9 is easier!

Google on "man egrep".

phppete
07-02-2007, 04:31 AM
Thanks for the info :)

garyamort
07-04-2007, 02:58 PM
How come this works fine on Apache 2


RewriteRule ^category/([\d]+)-([a-z0-9]+)/ category.php?id=$1 [QSA,L,NC]


but not on FQ, I finally tracked down that ^category/([\d]+) had to be changed to ^category/([0-9]+)



Out of curiosity, if \d is equivalent to 0-9, shouldn't

RewriteRule ^category/([\d]+)-([a-z\d]+)/ category.php?id=$1 [QSA,L,NC]


Be equivalent? (Basically, I don't understand why someone would change it in only one place instead of both)

phppete
07-04-2007, 03:07 PM
Out of curiosity, if \d is equivalent to 0-9, shouldn't

RewriteRule ^category/([\d]+)-([a-z\d]+)/ category.php?id=$1 [QSA,L,NC]


Be equivalent? (Basically, I don't understand why someone would change it in only one place instead of both)

Good question, I didn't notice that myself, probably because the second part was copied from a previous mod rewrite for another site I did where it was something like ^pages/([a-z0-9]+)/$ cms.php?page=$1.

As with most code you write, you change your style over time and looking back at code I have written 2 years ago would not be what I would write today and no doubt I will be thinking the same several years down the line.

Terra
07-04-2007, 03:24 PM
FWIW - I despise POSIX regex! :QTcrazy:

Long live PCRE regex!!! :QTthumb:

If I could have pounded it into Apache 1.3, I would have long ago with a sledgehammer...