2010-05-27 110 views
3

假設我有一個文件在 http://www.mydomain.com/user/10202.html丟失即user.php的 然後服務器給了我404頁默認的錯誤.... 比我以下內容添加到我的.htaccess文件URL重寫404頁

ErrorDocument 404 /404.html 

但它重定向我http://www.mydomain.com/404.html,而我想留在 http://mydomain.com/user/10202.html並顯示404.html我怎麼能做到這一點...

+1

這是你的實際配置嗎?還有其他配置可能會與這個配置衝突嗎? – Gumbo 2010-05-27 10:47:10

回答

2

可以使用的RewriteCond重寫規則螞蟻從mod_rewrite的。

# If file doesn't exist, i display 404.html 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ /404.html [L] 
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中,我將錯誤記錄到調試數據庫中。