PDA

View Full Version : RewriteCond -d and -f flags


jackuess
12-05-2006, 04:25 AM
I'm trying to figure mod_rewrite out, and I find it a bit hard so far. I want all the scripts of my site to go trough my index.php script in the root.
This is my .htaccess:
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /test

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME} !(.*\.(css))$
RewriteRule ^(.+)$ index.php?page=$1 [L]
When, for example, going to test/articles the page parameter is set to 'index.php', which exists in articles, but I want it to be 'articles/index.php'. However if I comment out the first line, the page parameter is set to 'articles/', which is fine, but i need it to work with files, as well as directories.

I'm probably doing it wrong all together, but i would appreciate some directions.

Noodles24
01-15-2007, 10:51 AM
I always use the RewriteCond %{REQUEST_FILENAME} !-f e.g.:


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1&%{QUERY_STRING} [L]


This means anything that isn't a file or a directory is put through index.php. Which means it doesn't screw up existing things like images, css, admin pages, etc.