将 index.html 附加到根目录 [英] Append index.html to root directory

查看:40
本文介绍了将 index.html 附加到根目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的新网站有问题.(www.example.com)

I have a problem with my new site. (www.example.com)

基本上,当我查看我的 google 分析页面时,它认为 mysite/index.html 和 mysite/是两个不同的页面.这主要是出于 SEO 原因的问题.

Basically, when I look at my google analytics page, it considers mysite/index.html and mysite/ to be two different pages. This is problematic mainly for SEO reasons.

有没有办法将两者附加或使根自动重定向到 mysite/index.html?我想你可能可以通过 301 重定向或修改 .htaccess 文件来做到这一点.

Is there a way to append the two or make the root automatically redirect to mysite/index.html? I figured you probably can do this with either a 301 redirect or by modifying the .htaccess file.

顺便说一下,我的主机是 iPage.

My host is iPage by the way.

谢谢

推荐答案

您可以在 Apacher 服务器上通过将以下代码添加到位于根目录的 .htaccess 文件来完成此操作:

You are able to accomplish this on an Apacher server by adding the following code to an .htaccess file located in the root:

RewriteEngine On
RewriteBase /
RewriteRule ^$ http://www.example.com/index.html [R=301,L]

这会将任何请求都发送到/"并将它们重写为/index.html".我个人认为附加 index.html 比替代方法更丑陋,所以这里有一些 .htaccess 代码,用于从 URL 中删除 index.html:

This takes any requests to just '/' and rewrites them to '/index.html'. I, personally, feel that appending the index.html is uglier than the alternative, so here is some .htaccess code for removing index.html from the URL:

RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ http://www.example.com/ [R=301,L]

这篇关于将 index.html 附加到根目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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