【问题标题】:htaccess querystring redirecthtaccess 查询字符串重定向
【发布时间】:2013-12-10 10:51:03
【问题描述】:

我需要将大量添加了随机数的页面重定向到页面 url 的末尾,我需要将这些页面重定向到单个 url,但整个网站都会有大量的 url,例如;

http://www.domain.com/a002-product-ring-50134.html

http://www.domain.com/a002-product-ring-50140.html

http://www.domain.com/a002-product-ring-50145.html

http://www.domain.com/a002-product-ring-50168.html

http://www.domain.com/a002-product-ring-50384.html

http://www.domain.com/a002-product-ring-50393.html

http://www.domain.com/a002-product-ring-50404.html

这些需要重定向到http://www.domain.com/a002.html,但我唯一需要查询的是号码,所以我认为这样的事情会起作用;

Redirect 301 /a002-product-ring-(*).html http://www.domain.com/a002.html

【问题讨论】:

    标签: regex apache .htaccess redirect


    【解决方案1】:

    您需要使用RedirectMatch 来获得正则表达式功能:

     RedirectMatch 301 (a.+?)-product-ring-[^.]+\.html$ http://www.domain.com/$1.html
    

    【讨论】:

    【解决方案2】:

    我们可以使用 RewriteCond 并匹配 uri 模式如下。

    RewriteCond %{REQUEST_URI} ^.*(hello.html|contact_us.php)$

    重写规则 ^/(.*) http://www.domain.com/a002.html [R=302,L]

    【讨论】:

      猜你喜欢
      • 2015-03-31
      • 1970-01-01
      • 1970-01-01
      • 2017-04-13
      • 2010-11-06
      • 2014-05-10
      • 2011-08-03
      • 1970-01-01
      相关资源
      最近更新 更多