繁体   English   中英

将所有请求重定向到index.php .htaccess

[英]Redirect all requests to index.php .htaccess

这是我的.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.

请帮我解决这个问题?

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

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

签出此serverfault答案

总之, [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]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM