我有一个非常简单的5页静态网站。
当访问者访问不存在的页面时,我希望对索引页进行301重定向,而不是404。我试过这样的事情:
ErrorDocument 404 404.htm
redirect 301 404.htm index.htm
但这似乎不起作用。如何让它重定向到索引页面?
答案 0 :(得分: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]