我正在嘗試編寫一個.htaccess文件來引導併發送帶有錯誤代碼的索引。示例index.php?error404或index.php?error501。使用.htaccess捕獲錯誤
我可以使用下面的代碼在根目錄中指示錯誤。
ErrorDocument 404 index.php?error=404
ErrorDocument 501 index.php?error=501
例子http://www.domain.com/file_does_not_exist.php這個工作。 結果http://www.domain.com/index.php?error=404
問題是從子目錄捕獲併發送到index.php錯誤。
示例http://www.domain.com/directory_does_not_exist或 http://www.domain.com/directory_and/file_does_not_exist.php。
結果是http://www.domain.com/directory_does_not_exist/index.php?error=404因此index.php的CSS中斷了。
我嘗試了下面的代碼沒有成功。我正在嘗試通過重寫URL來重定向到index.php。
RewriteCond $1 !^err[45][0-9][0-9]$
RewriteRule ^\/.\/\.php$ /index.php?s=$1 [R]
AND
RewriteCond $1 !^err[45][0-9][0-9]$
RewriteRule ^([/]?*)\.php$ /index.php?s=$1 [QSA,L]
任何幫助,將不勝感激。
快速正確! – undone 2012-02-21 03:45:43