2011-08-23 82 views
0

我想重定向到错误页面,如果页面未找到。所以我在.htaccess文件中添加了这段代码。找不到htaccess 404问题?

# '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> 

回答

0

要开始使用 - 将所有ErrorDocument指示出<IfModule mod_rewrite.c> - 没有必要在所有的这一点。

现在它告诉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> 

附: 我也修改了您的重写规则:将它们连接在一起成为单个规则。

+1

我已经试过这个,但它不会工作。 –

+0

那么你看到了什么错误?是共享主机吗?或者您完全控制了服务器?出于安全/性能的目的,可能完全不处理.htaccess文件/忽略。如果它是你的服务器,那么你可能需要在服务器配置中的适当位置添加'AllowOverride All'指令。否则(如果它是共享托管服务器)联系您的托管公司。 – LazyOne