具有著名的!-f和!-d条件的RewriteCond无法正常工作

时间:2018-07-11 07:08:42

标签: apache .htaccess mod-rewrite

我有.htaccess个文件,其中包含以下指令:

RewriteEngine on

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

相当基本的重定向。但是,我的apache日志文件中出现无限内部循环,浏览器中出现500错误。 apache日志文件具有以下内容:

r->uri = /amit/public/activities.php.php.php.php.php.php.php.php.php
redirected from 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/activities.php
redirected from r->uri = /activities.php

那是我进入带有扩展名的页面的时候。当我尝试访问不带扩展名的页面时,没有任何区别。该页面存在,并且我已经仔细检查了所有内容,但是在我看来,主要问题是RewriteCond。

感谢您的帮助。

2 个答案:

答案 0 :(得分:1)

您不需要4个条件,而需要将它们与在一起:

INSERT INTO table2 (UserName, UseePass) 
SELECT Name, Password FROM table1

答案 1 :(得分:0)

感谢@anubhava。我刚刚意识到我的代码对所有服务器变量都使用$。它应该是%。愚蠢的错字打乱了我的大脑将近24小时...因此,@ anubhava提出的“最终”代码将是:

Options +FollowSymlinks
RewriteEngine on

RewriteBase /amit/public/

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

像魅力一样工作。