问题
I have an Apache .htaccess file in the parent directory to directory this .htaccess file is currently located. This works perfectly redirecting all requests as required. However, I would like it so in this directory, if the request is for a valid file (and NOT a directory), ignore the main rewrite rule.
Currently, the following turns off the rewrite for directories as well, and I can't 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 anyone who contributes.
回答1:
Try REQUEST_FILENAME
instead of REQUEST_URI
:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule . - [L]
REQUEST_URI
does only contain the URI path but Apache needs an absolute file system path to test agains -d
and -f
. And REQUEST_FILENAME
holds the absolute file system path corresponding to the current requested URI.
来源:https://stackoverflow.com/questions/1399090/mod-rewrite-redirect-if-anything-but-a-file