【问题标题】:.htaccess redirect traffic hitting .html links to TLD homepage.htaccess 将流量重定向到 TLD 主页的 .html 链接
【发布时间】:2012-02-29 00:38:27
【问题描述】:

我正在帮助客户将在网址末尾使用 .html 扩展名的旧网站迁移到正确命名的 URL 结构。我想将所有以 .html 结尾的 URL 重定向到主页。

我试过了,但没用:

RewriteRule ^(.*)\.html$ $1http://domain.org [NC]

【问题讨论】:

  • 文件是否在同一个域(domain.org)?

标签: apache .htaccess mod-rewrite redirect


【解决方案1】:

这样的东西应该适合你的需要:

RewriteEngine On 
RewriteBase /
RewriteRule (.*)\.html$ / [QSA,R=301,NC,L]

【讨论】:

    【解决方案2】:

    你可以这样使用:

      RewriteEngine On 
      RewriteBase /
      RewriteCond %{SCRIPT_FILENAME} !-f
      RewriteRule ([^/]+)\.html$ index.php?page=$1 [L,NC]
    

    或永久重定向

      RewriteEngine On 
      RewriteBase /
      RewriteCond %{SCRIPT_FILENAME} !-f
      RewriteRule (.*)\.html$ / [R=301,NC,L]
    

    【讨论】:

    • 我还要为主页添加一个案例
    【解决方案3】:

    您的问题不是很清楚,但仅基于您的代码,我认为这对您有用:

    RewriteRule \.html$ http://domain.org/? [R,L,NC]
    

    这会将每个以 .html 结尾的 URL 重定向到 http://domain.org/,甚至去除原始 URI 中的任何查询参数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-08
      • 2014-10-06
      • 2012-10-30
      • 2021-05-02
      • 1970-01-01
      • 2010-12-30
      • 1970-01-01
      • 2011-07-17
      相关资源
      最近更新 更多