【问题标题】:.htaccess 301 re-directing .html pages to sitemap.html.htaccess 301 将 .html 页面重定向到 sitemap.html
【发布时间】:2014-10-24 17:13:59
【问题描述】:

我尝试了两种方式将 .html 页面 301 重定向到 sitemap.html,但都没有。

  • 我一遍又一遍地检查了这段代码。
  • 我使用了 .htaccess 检查器/验证器,它们没有显示任何错误。
  • 相同的代码适用于文件夹到文件夹的重定向 - 这仅适用于从 .html 文件到 sitemap.html 的重定向。

问题:

页面应重定向到 www.example.com/sitemap.html

而是将它们重定向到 www.example.com/sitemap.htmlpage.html

换句话说,.htaccess 以某种方式将文件名放在 sitemap.html 之后。

我用过这两种方法:

1:

RewriteRule ^directory/(.*)$ /sitemap.html$1 [R=301,NC,L]

在第一个中,目录中的所有文件都应该重定向到sitemap.html。请注意,该类别的索引页面可以很好地重定向,但其中的 .html 结束页面却不能。

2:

redirect 301 /directory/page.html http://www.example.com/sitemap.html

我也尝试过单独重定向每个页面,结果相同。

知道这里有什么问题吗?

【问题讨论】:

    标签: .htaccess redirect


    【解决方案1】:

    您不应使用 capture 将所有内容重定向到 /sitemap.xml。只需在 root .htaccess 中使用这样的规则:

    RewriteEngine On
    
    RewriteRule ^directory/ /sitemap.html [R=301,NC,L]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-11
      • 1970-01-01
      • 1970-01-01
      • 2013-09-12
      • 1970-01-01
      • 2012-03-20
      • 1970-01-01
      相关资源
      最近更新 更多