2012-02-21 8 views
1

エラーコードを指定してインデックスを送信して送信するために、.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] 

ご協力いただければ幸いです。

答えて

3

書き換えを使用する必要はありません。例に

ErrorDocument 404 /index.php?error=404 
ErrorDocument 501 /index.php?error=501 

The docsショー絶対URL:ちょうどあなたのErrorDocumentディレクティブ(/でそれらを開始)で、絶対URLを使用

ローカルWEB-ためのスラッシュ(/)で始めることができ

のURLパス(DocumentRootからの相対パス)、またはクライアントが解決できる完全なURLでなければなりません。あるいは、ブラウザによって表示されるようにメッセージを提供することができる。例::

ErrorDocument 500 http://foo.example.com/cgi-bin/tester 
ErrorDocument 404 /cgi-bin/bad_urls.pl 
ErrorDocument 401 /subscription_info.html 
ErrorDocument 403 "Sorry can't allow you access today" 
+0

fast&correct! – undone

関連する問題