[英]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.我把一个庞大、复杂的网站改成了一个小的单页网站,所以用户需要从 404s 重定向到 index.html。
I put this in .htaccess :我把它放在.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 .如果您键入mydomain.com/lalalalala ,这将重定向到主页内容 ( mydomain.com/index.html ),但 URL 栏仍显示mydomain.com/lalalalala 。
How do I redirect 404s to index.html and rewrite the URL to mydomain.com ?如何将 404 重定向到index.html并将 URL 重写为mydomain.com ?
EDIT:编辑:
I'm using Bluehost.我正在使用 Bluehost。
You can use these 2 lines at the top of your .htaccess:您可以在 .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. DirectoryIndex
将使http://domain.com/
默认加载http://domain.com/index.html
并且在ErrorDocument
使用http://
将使其重定向到新的 URL。
Try below code :试试下面的代码:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . / [L,R=301]
ErrorDocument 404 /index.php
It's any 404 url
to your home page.
它是指向您
home page.
的任何404 url
home page.
DirectoryIndex index.html
ErrorDocument 404 http://example.com/
this would work for broken links.这适用于断开的链接。 apply in
.htaccess
file and then check any broken link tool.在
.htaccess
文件中应用,然后检查任何损坏的链接工具。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.