url重写为404页面

时间:2010-05-27 10:42:05

标签: php .htaccess

假设我丢失了一个文件 http://www.mydomain.com/user/10202.html即user.php 然后服务器给我404页面默认错误.... 我将以下内容添加到我的.htaccess文件

ErrorDocument 404 /404.html

但是当我想留下时,它会将我重定向到http://www.mydomain.com/404.html http://mydomain.com/user/10202.html并显示404.html我该怎么做...

2 个答案:

答案 0 :(得分:2)

你可以使用mod_rewrite的RewriteCond ant RewriteRule。

# If file doesn't exist, i display 404.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /404.html [L]

答案 1 :(得分:2)

我在.htaccess中使用这两行,链接仍然存在于不存在的位置(它不会重定向到error_404.html)

ErrorDocument 404 /error_404.html
RewriteRule ^error_([0-9]+).(html|php)$ error.php?error=error$1 [QSA,NC]

这适用于不存在的实际文件,但也适用于未正确匹配的重写文件。在error.php中,我将错误记录到调试数据库中。

相关问题