apache - .htaccess 500 错误 - 内部重定向循环

标签 apache .htaccess mod-rewrite

假设/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/

相关文章:

apache - .htaccess 如何工作?

apache - 使用 Socket.IO 的 NGINX 配置

java - 我无法访问 Apache Tomcat 管理器?

php - 使用 iframe 在 SSL 站点上显示具有绝对 URL 的非 SSL 内容

.htaccess - htaccess 重写多个文件夹

apache - 将.htaccess转换为nginx(mod_rewrite)

apache - URL 重写如何工作?

apache - Node.js 在 Windows 上表现不佳吗,它的基本 I/O 肯定不会比 apache 慢

.htaccess - TYPO3 在 FE 中强制使用 HTTPS

php - zend 框架重定向问题 : Invalid controller specified