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 不存在页面/位置TIRGERING 500服务器错误_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Apache 不存在页面/位置TIRGERING 500服务器错误

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}

我正在用服务器响应测试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} ^.*/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]