【问题标题】:Redirect subfolder to index.html in htaccess将子文件夹重定向到 htaccess 中的 index.html
【发布时间】:2013-06-06 08:52:49
【问题描述】:

我必须将子目录(子文件夹)重定向到他们的 index.html 页面。我怎样才能通过htaccess文件来做到这一点。

例如

http://www.annonline.com/itineraries-prices/

当我输入这个网址时,它应该被转发到

http://www.annonline.com/itineraries-prices/index.html

我该怎么做?

【问题讨论】:

  • 为什么需要这个?通常,当您进入该目录时,应该会自动调用 index.html。
  • 我也必须在 url 中显示 index.html。 Bcoz google 读取同一个文件的两个 url:'annonline.com/itineraries-prices/';和“annonline.com/itineraries-prices/index.html”; – Amit Jha 10 分钟
  • 这就是rel=canonical 的用途,但是可以重写并且非常简单。你尝试了什么?

标签: apache .htaccess


【解决方案1】:

避免谷歌重复您的页面的解决方案是包括:

<link rel="canonical" href="http://www.example.com/product.php?item=swedish-fish" />

在页面的 head 部分。详情请访问google blog

除此之外,在 apache 级别,DirectoryIndex 指令设置要查找的资源列表(请参阅apache docs
Ej:此指令设置在请求目录时要查找的资源

DirectoryIndex index.php index.html  

如果你想让 google 看到相同的资源,你应该做一个客户端重定向:

RewriteRule ^/itineraries-prices/?$ http://www.annonline.com/itineraries-prices/index.html [R=301,L]

【讨论】:

    猜你喜欢
    • 2014-06-17
    • 1970-01-01
    • 2015-05-30
    • 2017-12-05
    • 2012-11-23
    • 2011-06-13
    • 2013-11-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多