如何将 404 重定向到 index.html 并将 URL 重写为主页 URL? [英] How do I redirect 404's to index.html and rewrite the URL to the home page URL?
问题描述
我把一个庞大而复杂的网站改成了一个小的单页网站,所以用户需要从 404 重定向到 index.html.
I changed a bulky, complex website into a small one-page website, so users need to be redirected from 404s to index.html.
我把它放在 .htaccess 中:
ErrorDocument 404 /index.html
如果您输入 mydomain.com/lalalalala,这将重定向到主页内容 (mydomain.com/index.html),但 URL 栏仍显示 mydomain.com/lalalalala.
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.
如何将 404 重定向到 index.html 并将 URL 重写为 mydomain.com?
How do I redirect 404s to index.html and rewrite the URL to mydomain.com?
我正在使用 Bluehost.
I'm using Bluehost.
推荐答案
您可以在 .htaccess 的顶部使用这两行:
You can use these 2 lines at the top of your .htaccess:
DirectoryIndex index.html
ErrorDocument 404 http://domain.com/
DirectoryIndex
将使 http://domain.com/
默认加载 http://domain.com/index.html
并且在 ErrorDocument
中使用 http://
将使它重定向到新的 URL.
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.
这篇关于如何将 404 重定向到 index.html 并将 URL 重写为主页 URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!