【问题标题】:Redirect all requests to index.php .htaccess将所有请求重定向到 index.php .htaccess
【发布时间】:2016-11-30 10:35:57
【问题描述】:

这是我的 .htaccess 文件:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

我收到 500 内部服务器错误。在此命令之后: cat /var/log/apache2/error.log 我收到了这个错误:

AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

请帮我解决这个问题?

【问题讨论】:

  • 那么这个规则不会导致rewrite loop
  • 什么版本的apache?

标签: php apache .htaccess


【解决方案1】:

将您的 htaccess 规则更改为以下,然后它将起作用。

   RewriteEngine On
   RewriteBase /
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.+)$ /index.php/$1 [L,QSA]

【讨论】:

    【解决方案2】:

    结帐this serverfault answer

    总而言之,[L] 仅停止对当前规则集的处理,并将重写的 URL 传递回 URL 解析引擎,后者可能会再次应用您的规则集。 10倍。然后 Apache 说停止。

    如果重写已经到index.php,你可以添加一个不重写的条件:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !=/index.php
    RewriteRule . index.php [L]
    

    或者,您可以在其他规则之前检查 ENV:REDIRECT_STATUS 并停止应用任何其他规则:

    RewriteEngine On
    
    RewriteCond %{ENV:REDIRECT_STATUS} 200
    RewriteRule ^ - [L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php [L]
    

    【讨论】:

      猜你喜欢
      • 2015-04-10
      • 1970-01-01
      • 2012-12-07
      • 1970-01-01
      • 2012-11-16
      • 1970-01-01
      • 1970-01-01
      • 2013-08-26
      • 1970-01-01
      相关资源
      最近更新 更多