从rewriterrule中忽略/排除文件夹


htaccess ignore/exclude folders from RewriteRule

我有这样的脚本:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/?(images|orders)/
RewriteRule ^(.*)$ index.php?til=$1 [L,QSA]

在我的本地主机上可以正常工作但是当我把它上传到我的主机并进入www.domain.com/images/时它会重定向到index.php?til=403.shtml

mod_rewrite重复扫描htaccess文件,直到没有更多的替换。[L]标志表示"此循环中的最后一个"。w.e.f. Apache 2.4的[End]标志可以满足您的要求。有关更多讨论,请参阅我的调试.htaccess重写规则的技巧。

我怀疑问题是共享主机启用了多视图,而你没有在你的开发实例上。始终尝试使您的开发实例尽可能地与托管提供商保持一致。如果您不需要它,那么请始终关闭multiviews。

你总是可以通过添加[NS]标志在每个规则的基础上禁用它。在这种情况下,你把它添加到第一条规则,然后你会发现它现在工作了。

好的,这似乎工作。

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/orders/.* [NC]
RewriteCond %{REQUEST_URI} !^/401.shtml [NC]
RewriteCond %{REQUEST_URI} !^/403.shtml [NC]
RewriteRule ^(.*)$ index.php?til=$1 [L,QSA]