如何在不显示错误页面的URL的情况下显示404错误页面?

时间:2015-07-05 14:17:02

标签: php apache .htaccess mod-rewrite

当我的用户输入不存在的页面时,例如

www.example.com\wrongurl.html

我希望用户看到404错误页面。但URL不应该改变。

我尝试了以下但不起作用。

ErrorDocument 404 http://www.example.com/404.html

RewriteEngine On
RewriteRule 404/ http://www.example/404.html [NC]

我该怎么做?

1 个答案:

答案 0 :(得分:2)

请尝试以下规则:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^ /404.html [L,NC]

这在内部将对不存在的文件/目录的请求重定向到404.html页面。