Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 与名人一起改写-f和-d条件不起作用_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Apache 与名人一起改写-f和-d条件不起作用

Apache 与名人一起改写-f和-d条件不起作用,apache,.htaccess,mod-rewrite,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 ^(.*[^/])/?

我有
.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
这时,我进入带有扩展名的页面。当我尝试在没有扩展名的情况下访问页面时,没有任何区别。页面存在,我已经仔细检查了所有内容,但在我看来,主要问题是重写


非常感谢您的帮助。

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

RewriteEngine on
RewriteBase /amit/public/

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

感谢@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]

工作起来很有魅力。

仍然没有打破循环。我尝试过不同的版本,包括这个。这是完整的文件。等等,我想我刚刚发现了问题。在
RewriteCond
之后,让我测试一下变体
%
$
试试我更新的代码,并告诉你的URI导致这500个错误。请避免根据另一个答案发布问题的答案。您不需要
-s
-l
条件