Apache .htaccess 404错误重定向

Nat*_*han 0 apache .htaccess

我正在尝试制作一个htaccess文件,它将通过index.php重定向所有404错误.我希望用户无法访问的页面附加到index.php的URL,以便我可以找出哪个页面请求失败.

例如,如果他们尝试访问http://example.com/doesntexist.php,则apache应将其重定向到http://example.com/index.php/doesntexist

这就是我所拥有的:

RewriteCond %{REQUEST_FILENAME}  !-l
RewriteCond %{REQUEST_FILENAME}  !-d
RewriteCond %{REQUEST_FILENAME}  !-f
RewriteRule .* index.php?%{QUERY_STRING} [L]
Run Code Online (Sandbox Code Playgroud)

这适用于我的一个虚拟主机,但是当我将网站转移到另一个虚拟主机(GoDaddy)时失败了.

多谢你们

Pek*_*ica 5

我现在无法测试,但根据这个答案,当你设置一个

ErrorDocument /404.php
Run Code Online (Sandbox Code Playgroud)

(或index.php,没关系)

$_SERVER["REQUEST_URI"]变量将包含原始的失败请求.