使用mod_rewrite的Apache内部重定向无限循环 [英] Apache Internal Redirect Infinite Loop with mod_rewrite

查看:214
本文介绍了使用mod_rewrite的Apache内部重定向无限循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,即使已经为类似的问题提供了所有解决方案,这似乎也无法解决。

Okay, this seems impossible to solve, even with all the solutions already given to similar problems.

具有 .htaccess 文件,其代码如下:

Have .htaccess file with the following code:

RewriteEngine on

RewriteBase /amit/public/

RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]

RewriteCond ${REQUEST_FILENAME} !-f
RewriteCond ${REQUEST_FILENAME} !-d
RewriteRule ^(.*[^/])/?$ $1.php [NC,L]

没有 RewriteCond%{ENV:REDIRECT_STATUS} 200 和条件后的规则,服务器将经历无限循环。 apache日志文件如下所示:

Without the RewriteCond %{ENV:REDIRECT_STATUS} 200 and the rule following the condition, the server goes through infinite loop. The apache log file would look like this:

r->uri = /amit/public/activities.php.php.php.php.php.php.php.php
redirected from r->uri = /amit/public/activities.php.php.php.php.php.php.php
redirected from r->uri = /amit/public/activities.php.php.php.php.php.php
redirected from r->uri = /amit/public/activities.php.php.php.php.php
redirected from r->uri = /amit/public/activities.php.php.php.php
redirected from r->uri = /amit/public/activities.php.php.php
redirected from r->uri = /amit/public/activities.php.php
redirected from r->uri = /amit/public/activities.php
redirected from r->uri = /amit/public/activities

基本上,它不会在打开文件时打开评估为request_path.php,但会继续添加更多 .php s。

Essentially, it will NOT open the file when it evaluates to requested_path.php but will keep on adding more .phps.

如果我添加了该条件,它根本不会添加.php并在我的日志中显示以下行并返回404错误:

If I do add in that condition, it will not add .php at all and return 404 error with this line in my log:

File does not exist: /Applications/MAMP/htdocs/amit/public/activities

尝试将其关闭关闭24小时,没有运气...

Busted closed to 24 hours trying to solve it, no luck...

推荐答案

您正在使用 $ 代替%{REQUEST_FILENAME} c $ c>:

You’re using $ instead of % for %{REQUEST_FILENAME}:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*[^/])/?$ $1.php [NC,L]

当文件不存在时,仍然会导致重定向循环。您可以检查是否也添加了扩展名:

That would still cause a redirect loop when the file doesn’t exist. You can check if the extension was added too:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*[^/])(?<!\.php)/?$ $1.php [NC,L]

这篇关于使用mod_rewrite的Apache内部重定向无限循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆