htaccess忽略目录及其子目录


htaccess Ignoring directory and its subdirectories

我的htaccess文件中有以下内容:

<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>

如果我在mailinglist目录中,我基本上想删除最后一行的htaccess。

这只适用于/mailinglist目录根目录中的项目。一旦我像/mailinglist/w/1那样深入,它就会打破并达到最后一条重写规则。如果我在/mailinglist目录中,如何阻止它处理最后一条重写规则。

原因是我在那个目录中有一组不同的htaccess,我不希望这个htaccess控制它

尝试:

<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>

我刚刚将mailinglist的检查切换为RewriteCond。只有当URI不是以mailinglist开头时,条件才会重写为index.php。

条件应用于错误的规则,您需要围绕您的规则进行交换:

<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>

条件仅适用于紧随其后的规则,因此2个!-f!-d条件被误用为直通,而index.php规则缺少这些条件。