如何将404重定向到index.html并将URL重写为主页URL? [英] How do I redirect 404's to index.html and rewrite the URL to the home page URL?

查看:207
本文介绍了如何将404重定向到index.html并将URL重写为主页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 ),但网址栏仍然显示 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 并将网址重写为 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:// do默认使用main.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆