简体   繁体   English

如何将 404 重定向到 index.html 并将 URL 重写为主页 URL?

[英]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.

相关问题 如何从家庭URL删除index.html? - How to remove index.html from home URL? 如何使网站正常工作,以使“index.html”不会出现在网站名称之后的主页链接上? - How do I make a website work so that "index.html" does not appear on my home page's link after the website name? 将/和index.html重定向到新的新URL - Redirect / and index.html to a new new url Firebase 托管索引。html 仅在 URL `/index.html`,默认/主页“找不到站点”中指定时显示 - Firebase hosting index.html only shows when specified in the URL `/index.html`, default/home page "Site not found" 有什么方法可以阻止从重定向到主页index.html? - is there any way to stop from redirect to home page index.html? 如何将 index.html 重定向到 Wordpress 站点? - How do I redirect index.html to a Wordpress site? 使用htaccess将所有请求重定向到主页(在URL中隐藏index.html) - Redirect all requests to main page using htaccess (hide index.html in URL) 在网址中隐藏index.html - hide index.html in the URL 如何在index.html主页上显示wordpress登录表单? - How to display wordpress login form on index.html home page? 如何使用我设计为Wordpress网站主页的index.html? - How to use the index.html I've designed as the home page of a Wordpress website?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM