[thelist] mod_rewrite regex help

Joshua Olson joshua at waetech.com
Mon Dec 20 20:08:57 CST 2004

> -----Original Message-----
> From: Matt Warden
> Sent: Monday, December 20, 2004 8:13 PM
> Hello list,
> I have the following rules in my .htaccess file:
> RewriteEngine On
> RewriteRule ^/collab.*$ $1 [NC,L]
> RewriteRule \.(php|htm|html)$ /server.php?q=$1 [NC,L]
> RewriteRule ^[^\.]*$ /server.php?q=$1 [L]

> But, my main question has to do with th is just not working at all. I
> tested my regex's and they seem to match correctly, but I am getting
> 500 errors in the apache logs when I test things. For example:


In the example above, it doesn't appear that you've indicated in the rules
exactly what $1 is going to be.  You accidentally defined in in #2 when you
added to OR clause.  I would start be changing the rules for 1 and 3 thusly:

RewriteRule ^(/collab.*)$ $1 [NC,L]
RewriteRule ^([^\.]*)$ /server.php?q=$1 [L]

Then, for #2, you don't seem to have the entire URI accounted for within the
regex.  Something like this may provide the desired results:

RewriteRule ^(.*\.(php|htm|html))$ /server.php?q=$1 [NC,L]

That may solve your immediate need.  But, I'd warn you that your regex for
#1 is not fool proof... for example, the following string would match #1:


I'd suggest to you that you take another look at how you developed that
regex and eliminate such holes.

For #3. you stated that you goal was to "match requests for the default page
of the root and other directories."  Presuming that folder names are not
allowed to have .'s in them, then you have likely accomplished what you set
out to do.


Joshua Olson
Web Application Engineer
WAE Tech Inc.

More information about the thelist mailing list