1

I have a very simple 5 page static site.

Instead of a 404, I want to do a 301 redirect to the index page whenever a visitor accesses a page that doesn't exist. I tried something like this:

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

but that doesn't seem to work. How would I get it to do a 301 redirect to the index page?

4

1 に答える 1

2

If you have only a fixed list of pages then you could do something like:

#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]
于 2011-03-12T21:24:08.463 に答える