【问题标题】:Redirect xyz.html/ to xyz.html on large scale大规模重定向 xyz.html/ 到 xyz.html
【发布时间】:2012-01-29 18:37:58
【问题描述】:

我有一个包含 50 多个 html 页面的简单 html 网站。从统计脚本中,我有时会在 xyz.html/ (重定向到 404)之类的页面上看到用户,而不是 xyz.html。我知道一个简单的方法是放置 301 重定向,但页面太多。谁能建议一种方法将所有传入流量重定向到带有正斜杠“/”的链接到没有正斜杠的页面? (流量通常来自社交媒体)

like 

abc.html/ to abc.html
xyz.html/ to xyz.html
.
.
.
so on

编辑:

我只想在特定目录而不是整个域上执行此操作。例如仅对 www.example.com/section/

   www.example.com/section/abc.html/ to www.example.com/section/abc.html
   www.example.com/section/xyz.html/ to www.example.com/section/xyz.html

【问题讨论】:

    标签: html .htaccess seo permalinks


    【解决方案1】:

    取决于您的服务器。对于 nginx,你需要一些类似的东西(虽然没有检查):

    location ~\.html/$ {
        rewrite (.*)/$ $1 last;
    }
    

    【讨论】:

      【解决方案2】:
       RewriteRule ^((.+)\.html)/$ http://<your-domain>/$1 [L,R=301]
      

      替换为您的域名(和文件夹,如果需要)。 响应基于此处提供的数据mod_rewrite: remove trailing slash (only one!)

      【讨论】:

      • 使用^(section/(.+)\.html)/$ 仅将规则应用于section 文件夹中的任何内容
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-21
      • 2013-01-21
      • 2014-10-31
      • 2012-12-11
      • 2018-05-28
      • 2020-12-20
      相关资源
      最近更新 更多