【问题标题】:301 Redirect for URL's with Query string带有查询字符串的 URL 的 301 重定向
【发布时间】:2011-03-15 04:47:45
【问题描述】:

我想对所有带有查询字符串的 url 执行 301 重定向到基本 url(没有查询字符串)。

例如:

  1. http://www.mysite.com/directory/abcbd.html?q1=23&q2=89 应该重定向到 http://www.mysite.com/directory/abcbd.html

    1. http://www.mysite.com/directorynew/file3.html?q1=213&q2=389&q3=ttim 应该重定向到 http://www.mysite.com/directorynew/file3.html

如上例所示,“q1=”将始终出现在相关网址的开头。下一组网址可能会有所不同。那么有没有类似的东西: RewriteCond %{query_string} "q1=.*" - 不擅长这些事情!

我需要在 .htaccess 文件中输入哪些条目?

谢谢, 萨米尔

【问题讨论】:

    标签: .htaccess http-status-code-301


    【解决方案1】:

    我会按照这条规则来做的:

    RewriteRule ^(.*)\?.*  $1  [L,R=301]
    

    【讨论】:

      【解决方案2】:

      其实我是使用 wp_redirect 插件完成的。

      来源:/(.)/(.).html(.)\?dontneedthisstring=(.) 目标:/$1/$2.html

      这会清理它。

      这里的“dontneedthisstring”是我试图摆脱的 uniq 字符串。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-04-10
        • 1970-01-01
        • 2015-05-27
        • 2015-07-16
        • 2012-04-25
        • 1970-01-01
        • 2015-08-12
        • 1970-01-01
        相关资源
        最近更新 更多