2011-08-23 12 views
0

ページが見つからない場合は、エラーページにリダイレクトします。ですから、このコードを.htaccessファイルに追加しました。htaccess 404に問題が見つかりませんか?

# '404 Not Found' error 
ErrorDocument 404 /index.php?p=error&code=404 

しかし、テストすると、index.phpファイルにリダイレクトされません。 <IfModule mod_rewrite.c>のうち、すべてのErrorDocumentディレクティブを動かす - - すべてでそのための必要はありません

私の全体の.htaccessファイルのコードが

#AuthName "Restricted Area" 
#AuthType Basic 
#AuthGroupFile /dev/null 
#require valid-user 
#<Files "/site/captcha/"> 
# Allow from all 
#</Files> 

<IfModule mod_rewrite.c> 
Options +FollowSymLinks 
RewriteEngine on 

## File paths are relative to the Document Root (/) 
# '400 Bad Request' error 
ErrorDocument 400 /index.php?p=error&code=400 
# '404 Not Found' error 
ErrorDocument 404 /index.php?p=error&code=404 
# '403 Forbidden' error 
ErrorDocument 403 /index.php?p=error&code=403 
# '401 Unauthorized' error 
ErrorDocument 401 /index.php?p=error&code=401 
# '500 Internal Server Error' 
ErrorDocument 500 /index.php?p=error&code=500 

############################# Pages ########################################################## 

RewriteRule ^home/$ index.php [S=1] 
RewriteRule ^home$ index.php [S=1] 

</IfModule> 

答えて

0

を開始するにはここにあります。

これはApacheに「mod_rewriteが有効な場合のみErrorDocumentを使用する」と伝えます。

今のところうまく動作しない場合は、mod_rewriteが実際に有効になっていない可能性が非常に高いです。あなたは<IfModule mod_rewrite.c>ブロック(それを前に)外にそれらを配置する場合(.htaccessファイルは、Apacheに認識され、処理されている限り)しかし、それは動作するはずです:

#AuthName "Restricted Area" 
#AuthType Basic 
#AuthGroupFile /dev/null 
#require valid-user 
#<Files "/site/captcha/"> 
# Allow from all 
#</Files> 

Options +FollowSymLinks 

# '400 Bad Request' error 
ErrorDocument 400 /index.php?p=error&code=400 
# '404 Not Found' error 
ErrorDocument 404 /index.php?p=error&code=404 
# '403 Forbidden' error 
ErrorDocument 403 /index.php?p=error&code=403 
# '401 Unauthorized' error 
ErrorDocument 401 /index.php?p=error&code=401 
# '500 Internal Server Error' 
ErrorDocument 500 /index.php?p=error&code=500 

<IfModule mod_rewrite.c> 
    RewriteEngine on 
    # Pages 
    RewriteRule ^home/?$ index.php [L] 
</IfModule> 

P.S.を 私はあなたの書き換えルールも変更しました。それらをまとめて1つのルールにしました。

+1

私はこれを試しましたが、うまく動作しません。 –

+0

あなたはどんなエラーを見ますか?それは共有ホスティングですか、あなたはサーバーを完全に制御できますか?セキュリティ/パフォーマンス目的で、.htaccessファイルがすべて処理されない/無視される可能性があります。それがあなたのサーバなら、 'AllowOverride All'ディレクティブをサーバ設定の適切な場所に追加する必要があります。それ以外の場合(ホスティングサーバーを共有している場合)、ホスティング会社にお問い合わせください。 – LazyOne

関連する問題