【问题标题】:RedirectMatch 301 for just html fileRedirectMatch 301 仅用于 html 文件
【发布时间】:2010-03-16 11:17:52
【问题描述】:

我需要为我的网站的所有以 .html 结尾的页面执行大规模 301 重定向。我希望将所有旧的 .html 文件移动到子文件夹 ir。

RedirectMatch 301 (.*)\.html$ http://www.domain.com/folder/$1.html

当我添加它并刷新浏览器时,我现在在 url ie 之后得到了大量的文件夹/文件夹/文件夹

domain.com/folder//文件夹/文件夹/文件夹.....

有什么想法可能是错的吗?

如果你能帮忙,谢谢

【问题讨论】:

  • 给出一个具体的例子,说明您要从哪个源 URL 重定向,以及您希望将其重定向到哪里。
  • 好吧,我要举一个更好的例子,正常的 301 是 RedirectMatch 301 file.html domain.com/folder/file.html

标签: mod-rewrite http-status-code-301


【解决方案1】:

问题是,'folder/foo.html' 也符合 RedirectMatch 的条件,并且文件夹被再次附加(一次又一次......)

因此,您可能需要这样的东西(未经测试):

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/folder/
RewriteRule (.*)\.html$ /folder/$1.html [R=301,L]

RewriteCond 应检查 URI 是否以 /folder 开头,并且只有满足此条件时,才会检查 RewriteRule。

不幸的是,我目前没有任何可用的 Apache 安装来测试这些东西,所以你可能不得不自己尝试一下。但我希望你明白了。

【讨论】:

    【解决方案2】:

    如果您的旧 html 文件位于根目录中,我建议如下:

    RedirectMatch 301 ^([^/]+)\.html$ http://www.domain.com/folder/$1.html
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-27
      • 2014-09-12
      • 2023-03-18
      • 2015-01-13
      • 1970-01-01
      • 1970-01-01
      • 2014-06-18
      相关资源
      最近更新 更多