Apache 不存在页面/位置TIRGERING 500服务器错误
我正在用服务器响应测试404和其他错误,404工作正常 我输入Apache 不存在页面/位置TIRGERING 500服务器错误,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,我正在用服务器响应测试404和其他错误,404工作正常 我输入example.com/page,example.com/directory/,example.com/directory/page,它将返回404个错误 然后我尝试了example.com/directory/page/string(比如这里的123或关键字),它返回了500个错误 我将此代码用于mod\u rewrite # redirects index.html to / RewriteCond %{THE_REQUEST}
example.com/page
,example.com/directory/
,example.com/directory/page
,它将返回404个错误
然后我尝试了example.com/directory/page/string
(比如这里的123或关键字),它返回了500个错误
我将此代码用于mod\u rewrite
# redirects index.html to /
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ /$1 [R=301,L]
# rewrites file.html to file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)$ $1.html [L,QSA]
如何将这500个错误转换为正确的404?很可能是循环,请尝试添加以下条件:
RewriteCond %{ENV:REDIRECT_STATUS} ^$
在你的最后规则。所以它看起来是这样的:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
# redirects index.html to /
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ /$1 [R=301,L]
# rewrites file.html to file
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)$ $1.html [L,QSA]
很可能是循环,请尝试添加以下条件:
RewriteCond %{ENV:REDIRECT_STATUS} ^$
在你的最后规则。所以它看起来是这样的:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
# redirects index.html to /
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ /$1 [R=301,L]
# rewrites file.html to file
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)$ $1.html [L,QSA]