Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
752 views
in Technique[技术] by (71.8m points)

.htaccess - How do I redirect 404's to index.html and rewrite the URL to the home page URL?

I changed a bulky, complex website into a small one-page website, so users need to be redirected from 404s to index.html.

I put this in .htaccess:

ErrorDocument 404 /index.html

If you type mydomain.com/lalalalala, this redirects to the home page content (mydomain.com/index.html), but the URL bar still says mydomain.com/lalalalala.

How do I redirect 404s to index.html and rewrite the URL to mydomain.com?

EDIT:

I'm using Bluehost.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use these 2 lines at the top of your .htaccess:

DirectoryIndex index.html
ErrorDocument 404 http://domain.com/

DirectoryIndex will make http://domain.com/ load http://domain.com/index.html by default and use of http:// in ErrorDocument will make it redirect to new URL.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...