htaccess Ignoring directory and its subdirectories

醉酒当歌 提交于 2020-01-07 05:10:10

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!