开发者

Problem in htaccess 404 not found?

i want to redirect to the error page if the page is not found. so i have add this code in .htaccess file.

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

but when i test it will not redirect to index.php file.

my whole .htaccess file code is here

#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 开发者_Go百科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>


To start with -- move all ErrorDocument directives out of <IfModule mod_rewrite.c> -- there is no need at all for that.

Right now it tells Apache: "use ErrorDocument ONLY IF mod_rewrite is enabled".

If it does not work for you right now, then it is extremely likely that mod_rewrite is not actually enabled. But if you place them outside <IfModule mod_rewrite.c> block (just before it), then it should work (as long as .htaccess is recognised and processed by 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. I have also modified your rewrite rules: jointed them together into single rule.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜