在我的重写规则中可能导致无限重定向循环的原因是,/ some / virtual / host是指向不同命名的物理位置的虚拟主机?通常我会检查日志,但这是一个很大程度上无法控制的暂存/生产环境。出于同样的原因,在违规目录中使用.htaccess不是一种选择。
<Location /some/virtual/host>
RewriteEngine On
RewriteCond %{REQUEST_URI} !/assets/ [OR]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php [L]
</Location>
答案 0 :(得分:0)
您可能不希望条件中包含[OR]
标记,因为当规则将URI重写为/index.php
时,它会匹配!/assets/
,因此规则会再次应用。 [OR]
标志使它不会检查该文件是否也不存在。
<Location /some/virtual/host>
RewriteEngine On
RewriteCond %{REQUEST_URI} !/assets/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php [L]
</Location>
但是这个可能不是你的目标。这完全取决于您希望通过RewriteCond %{REQUEST_URI} !/assets/
条件实现的目标。
编辑:
任何不是名为“assets”的目录中的现有文件的内容都应该重定向到index.php
我假设你想要资产目录中不存在的文件?然后::
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^assets/ index.php [L]
假设htaccess文件位于文档根目录中。您不需要<Location>
容器。