Apache 在.htaccess配置后显示500错误,而不是404错误

Apache 在.htaccess配置后显示500错误,而不是404错误,apache,.htaccess,Apache,.htaccess,我最近在.htaccess文件中添加了以下行: RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php RewriteRule ^/?(.*)\.php$ /$1 [L,R=301] RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/$ /$1 [L,R=301] RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^/?(.*)$

我最近在.htaccess文件中添加了以下行:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]
我正在努力实现的目标: 对于PHP文件:

example.com/abc.php should be redirected as example.com/abc
example.com/abc/ should be redirected as example.com/abc
example.com/abc should load as example.com/abc
对于目录,以正常行为加载: 注意:xyz是一个目录

example.com/xyz should load as example.com/xyz/
example.com/xyz/ should load as example.com/xyz/
问题是,如果有人尝试example.com/abc/bla,它会抛出500个错误,而不是404个错误。
有人能帮我修改上面的.htaccess行以修复500错误问题吗?

经过多次更正,我解决了这个问题。 这是htaccess的最终代码

# browser requests PHP
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]
#Enforce a no-trailing-slash policy.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# 404 ANY URL WITH ADDITIONAL PATH INFO ##
RewriteCond %{PATH_INFO} .
RewriteRule ^ - [R=404]
# check to see if the request is for a PHP file:
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]
此代码执行以下操作

example.com/abc.php redirecting as example.com/abc
example.com/abc/ redirecting as example.com/abc
example.com/abc showing as example.com/abc
example.com/abc/nopage redirecting to 404

我假设您在使用当前.htaccess的任何页面上都会出现500错误?或者这只发生在你给出的一个例子上?@Kinglish只抛出500个,例如.com/abc/anything,对于其他不存在的页面,例如example.com/blabla抛出400个错误,没有任何错误issue@ShafeequeM,500来自服务器的内部错误,你能告诉我们除了这些之外还有什么规则吗?把所有的行注释掉,然后一行一行地加回去。它会告诉你哪一行有问题。另外,将
logleveldebug
放入并检查日志文件。500是一个内部服务器错误,因此apache不喜欢配置中的某些内容。