2011-03-12 62 views
1

我有一个非常简单的5页静态网站。如何结合ErrorDocument和在htaccess中重定向?

而不是404,我想做一个301重定向到索引页面,只要访问者访问一个不存在的页面。我试过这样的事情:

ErrorDocument 404 404.htm 
redirect 301 404.htm index.htm 

但这似乎并不奏效。我将如何获得它301重定向到索引页?

回答

2

如果你只有页面的固定列表,那么你可以这样做:

#map _all_ known pages on the site 
RewriteRule url1 page1.htm [NC, L] 
RewriteRule url2 page2.htm [NC, L] 
RewriteRule url3 page3.htm [NC, L] 
RewriteRule url4 page4.htm [NC, L] 
RewriteRule url5 page5.htm [NC, L] 

#if there's something that doesn't fit in the rules above then it means there's no such page so we redirect to home with a 301 
RewriteRule (.+) index.htm [R=301,L] 
+0

或:URL重写规则([0-9] +)$页1.htm [NC,L] – 2011-10-07 11:52:18

+0

这是只有一个例子,他可以有5个页面,称为“一”,“二”,“三”,“四”和“五”,它们必须被重写为“first.htm”,“second.htm”,“third .htm','fourth.htm'和'fifth.htm'。你不能用一条规则来做到这一点。 – CyberDude 2011-10-07 14:06:16