Проблема в htaccess 404 не найдена? - PullRequest
0 голосов
/ 23 августа 2011

Я хочу перенаправить на страницу ошибки, если страница не найдена.поэтому я добавил этот код в файл .htaccess.

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

, но при тестировании он не будет перенаправлен в файл index.php.

весь мой код файла .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>

1 Ответ

0 голосов
/ 23 августа 2011

Для начала - уберите все директивы ErrorDocument из <IfModule mod_rewrite.c> - в этом вообще нет необходимости.

Сейчас он говорит Apache: «используйте ErrorDocument ТОЛЬКО ЕСЛИ mod_rewrite включенMsgstr ".

Если это не работает у вас сейчас, то очень вероятно, что 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>

PS Я также изменил ваши правила перезаписи: объединил их в единое правило.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...