我已经编辑我的.htaccess文件到以下内容:
ErrorDocument 404 /index.php?page=page-not-found ErrorDocument 400 /index.php?page=bad-request
现在错误404redirect正确,但如果我input一个地址如http:// newshell /%22 %% 5E $ %% 5E&%C2%A3&服务器不redirect400错误,但显示默认的apache消息。 我究竟做错了什么?
来自Apache文档的引用:
尽pipe大多数错误消息都可以被覆盖,但是在某些情况下,不pipeErrorDocument的设置如何,都使用内部消息。 特别是,如果检测到格式错误的请求,正常的请求处理将立即停止并返回内部错误消息。 这是必要的,以防止不良请求引起的安全问题。
所以,如果你想redirect错误400,你应该取消httpd.conf Apacheconfiguration文件中的ErrorDocument指令,如下所示:
# Some examples: #ErrorDocument 500 http://foo.example.com/cgi-bin/tester ErrorDocument 400 /cgi-bin/bad_request.pl #ErrorDocument 401 /subscription_info.html #ErrorDocument 403 "Sorry can't allow you access today"
并重新启动Apache服务器。