Mod_rewrite: redirect if something other than a file

I have an Apache.htaccess file in the parent directory for the directory of this .htaccess file. This works great, redirecting all requests as needed. However, I would like that in this directory, if the request contains a valid file (and NOT a directory), ignore the basic rewrite rule.

Currently the following disables rewriting for directories and I cannot figure out why.

<IfModule mod_rewrite.c>
 Options +FollowSymLinks
 Options +Indexes
 RewriteEngine On
 RewriteBase /
 RewriteCond %{REQUEST_URI} !-d
 RewriteCond %{REQUEST_URI} -f
 RewriteRule . - [L]
</IfModule>

      

Thanks to everyone who contributes.

+2


source to share


1 answer


Try REQUEST_FILENAME

instead REQUEST_URI

:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule . - [L]

      



REQUEST_URI

contains only the URI path, but Apache needs the absolute filesystem path to check for duplicates -d

and -f

. And REQUEST_FILENAME

contains the absolute filesystem path corresponding to the currently requested URI.

+1


source







All Articles