问题
I have the following in my htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(mailinglist)/.*$ - [L]
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
I basically want to remove htaccess from hitting that last line if I am in the mailinglist directory.
This only works for items in the root of the /mailinglist directory. Once I go deeper like /mailinglist/w/1 it breaks and hits that last rewrite rule. How do I stop it from processing that last rewrite rule if I am in the /mailinglist directory.
The reason is I have a different set of htaccess in that directory and I do not want this htaccess to control it.
回答1:
Try:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^(mailinglist)/.*$
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
I just switched the checking for mailinglist to be a RewriteCond. The condition will only rewrite to index.php if the URI doesn't begin with mailinglist.
回答2:
The conditions are being applied to the wrong rule, You need to swap around your rules:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(mailinglist)/.*$ - [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
Conditions only apply to the immediately following rule, so the 2 !-f and !-d conditions are being misapplied to the passthrough, while the index.php rule is missing those conditions.
来源:https://stackoverflow.com/questions/12396894/htaccess-ignoring-directory-and-its-subdirectories