.htaccess! -f does not work

I have been using simple mod_rewrite rules for my CMS for many years, and now I am making a new version, I see that rewriteCond does not make sense - I have the standard "if it is not a file", but I can still see that the rewriters though and were not expected. My rewrite code:

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

I load / page / var and it works fine like index.php? page = page & var = var, but am I trying to load /css/file.css and loading index.php? page = css & var = file.css, although there is a /css/file.css file, so the entire rewrite section should not be evaluated.

I have never seen htaccess seem to be challenging its own logic, can someone help me figure this out? Has anyone ever come across anything like this?

+12
.htaccess mod-rewrite
Mar 30 '09 at 16:21
source share
4 answers

RewriteCondition applies only to the following rule. You want this:

 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]+)$ index.php?page=$1 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]+)/([^/]+)$ index.php?page=$1&var=$2 
+25
Mar 30 '09 at 16:37
source share

If you are using Apache 2.2, you MUST read this:

http://amandine.aupetit.info/135/apache2-mod_rewrite/

Spoiler: what you need to write is actually:

 RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-l 

Merc.

+13
Sep 25 '12 at 1:29
source share

Well, that should work.

Try setting the following details in your .htaccess:

 RewriteLog /var/log/rewrite.log RewriteLogLevel 3 

Debugging your requests. Remember to reset this value as soon as you are done, otherwise you will get a full hard drive.

+3
Mar 30 '09 at 16:34
source share

Perhaps using RewriteLog and RewriteLogLevel to debug what it does?

(From http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html )

+1
Mar 30 '09 at 16:39
source share



All Articles