繁体   English   中英

.htaccess内部服务器错误:ErrorDocument无法正常工作(RewriteEngine on)

[英].htaccess Internal Server Error: ErrorDocument not working (RewriteEngine on)

每当我在我的ErrorDocument上有RewriteEngine时 - 部分不起作用。 这是我目前的.htacces文件:

ErrorDocument 404 404.php

Options -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$  /$1.php [QSA,L]

所以当我在浏览器中打开一个不存在的文件时,我得到一个500内部服务器错误,我没有被重定向到404.php文件。

请帮我 ;)

这是因为你盲目地将.php重写为URI的末尾。 让我们来看看当你转到404网址时会发生什么:

  • 你要求: http://example.com/blahblahhttp://example.com/blahblah
  • URI不是文件(传递!-f
  • URI不是目录(传递!-d
  • URI匹配(.*)
  • URI被重写为包含.php
  • URI现在是/blahblah.php
  • URI不是文件(传递!-f
  • URI不是目录(传递!-d
  • URI匹配(.*)
  • URI被重写为包含.php
  • URI现在是/blahblah.php.php
  • URI不是文件(传递!-f
  • URI不是目录(传递!-d
  • URI匹配(.*)
  • URI被重写为包含.php
  • URI现在是/blahblah.php.php.php

等等

您需要确保您正在重写的内容实际存在或导致循环:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.php -f
RewriteRule ^(.*)$  /$1.php [QSA,L]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM