阿帕奇的.htaccess 404错误重定向 [英] Apache .htaccess 404 error redirect
问题描述
我试图让一个htaccess文件,将通过index.php文件重定向所有404错误。我想用户无法访问附加到index.php文件的URL的网页,这样我可以找出哪些页面请求失败。
I'm trying to make an htaccess file that will redirect all 404 errors through index.php. I would like the page the user failed to access to be appended to index.php's URL so that I can find out what page request failed.
例如,如果他们试图访问 http://example.com/doesntexist.php ,阿帕奇应该重定向到 http://example.com/index.php/doesntexist
For example, if they tried to access http://example.com/doesntexist.php, apache should redirect them to http://example.com/index.php/doesntexist
这是我有:
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php?%{QUERY_STRING} [L]
这工作对我的主机商之一,但失败了,当我转移网站到另一个虚拟主机提供商(GoDaddy的)。
This works on one of my webhosts but failed when I transfered the site to another webhost (GoDaddy).
谢谢你们
推荐答案
我现在还不能测试这一权利,但根据<一个href="http://stackoverflow.com/questions/2048888/how-can-i-get-errordocument-in-htaccess-to-output-wrong-uri-parameter">this回答,当你设置一个
I can't test this right now, but according to this answer, when you set a
ErrorDocument /404.php
(或index.php文件,无所谓)
(or index.php, doesn't matter)
在 $ _ SERVER [REQUEST_URI]
变量将包含原始,失败的请求。
The $_SERVER["REQUEST_URI"]
variable will contain the original, failed request.
这篇关于阿帕奇的.htaccess 404错误重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!