Web Hosting Talk







View Full Version : Quick Mod Rewrite Question


GA PunkFreak
09-13-2007, 01:49 AM
Hello,

I apologize if this is a common question, but I can't seem to find a straight answer anywhere.

This line:
RewriteRule ^/([A-Za-z0-9-]+)/?$ index.php?content=$1

would also catch my /forums/ directory and send people to index.php?content=forums which doesn't exist. How do I avoid this problem?

Thanks in advance,
-Phil

isurus
09-13-2007, 05:03 PM
Use a RewriteCond directive before your RewriteRule, eg:

RewriteCond %{REQUEST_FILENAME} !^/forums
http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritecond

Jatinder
09-14-2007, 12:59 AM
Use this:


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/([A-Za-z0-9-]+)/?$ index.php?content=$1


This will prevent any directories or files that actually exist from being redirected.

GA PunkFreak
09-14-2007, 01:02 PM
Thanks guys. Worked perfectly :)