2011-03-12 45 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