【问题标题】:Append index.html to root directory将 index.html 附加到根目录
【发布时间】:2012-04-27 09:45:58
【问题描述】:

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

基本上,当我查看我的谷歌分析页面时,它认为 mysite/index.html 和 mysite/ 是两个不同的页面。这主要是出于搜索引擎优化的原因。

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

顺便说一句,我的主机是 iPage。

谢谢

【问题讨论】:

    标签: html indexing directory append root


    【解决方案1】:

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

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

    这会将任何请求仅接收到“/”并将它们重写为“/index.html”。我个人觉得附加 index.html 比其他方法更难看,所以这里有一些 .htaccess 代码,用于从 URL 中删除 index.html:

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

    【讨论】:

    • 谢谢老兄,这很好用,我只是将索引重定向到 .htaccess 中的 /
    猜你喜欢
    • 2015-03-09
    • 2017-02-20
    • 1970-01-01
    • 2014-04-25
    • 2016-09-19
    • 2013-07-06
    • 1970-01-01
    • 1970-01-01
    • 2018-03-02
    相关资源
    最近更新 更多