Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

PCRE with mod rewrite

2:41 pm on Nov 16, 2010 (gmt 0)

New User

5+ Year Member

joined:Oct 3, 2008
votes: 0

Anyone now if mod_rewrite engine includes an underscore with \w, like Perl, some engines don't as I understand it? I know rewrite supports the char class alnum.

\w = [a-zA-Z0-9_]
[:alnum:] = [a-zA-Z0-9]

RewriteCond %{QUERY_STRING} f=(\w+)
RewriteCond %{QUERY_STRING} f=([[:alnum:]_])

I'll have time to set up a test HTTP Server later but not today, so I can't test myself. Apologizes! I hate asking questions I can get the answer to myself but I need to know today.

4:07 pm on Nov 16, 2010 (gmt 0)

Preferred Member

10+ Year Member

joined:June 10, 2003
posts: 410
votes: 0

Apache supports PCRE, however it doesn't (appear to) know about things like [:alnum:] used. I was able to use \w and \d, for example.


10:55 pm on Nov 17, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
votes: 0

When in doubt, use the old-style POSIX expressions for best results (and portability). Use of the [NC] flag on the RewriteCond or RewriteRule (as applicable) can make this slightly less painful, so as to avoid having to specify both upper- and lower-case ranges.