假设/some/virtual/host 是指向不同名称的物理位置的虚拟主机,什么可能导致我的重写规则中出现无限重定向循环?通常我会检查日志,但这是一个在很大程度上超出我控制范围的暂存/生产环境。出于同样的原因,在有问题的目录中使用 .htaccess 不是一种选择。
<Location /some/virtual/host>
RewriteEngine On
RewriteCond %{REQUEST_URI} !/assets/ [OR]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php [L]
</Location>
最佳答案
您可能不想要 [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/
实现的目标条件。
编辑:
Anything that is not an extant file inside of a directory named "assets" should be redirected to index.php
我假设您想要 Assets 目录中不存在的文件?然后::
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^assets/ index.php [L]
假设 htaccess 文件位于您的文档根目录中。你不需要 <Location>
容器。
关于apache - .htaccess 500 错误 - 内部重定向循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20788140/