【问题标题】:Redirecting Specific URL pattern using REGEX使用 REGEX 重定向特定的 URL 模式
【发布时间】:2018-07-25 20:12:44
【问题描述】:

我想重定向网址

https://old-URL.com/index.php?topic={integers} 到 https://new-URL.com/index.php?topic={integers}

我试过了:

RewriteEngine On    
RewriteRule ^\/index\.php\?topic=(.*) https://new-URL.com/ [R=301]

但我似乎一辈子都得不到它。

【问题讨论】:

    标签: regex .htaccess url


    【解决方案1】:

    您无法匹配 RewriteRule 模式中的 URL QueryString (?topic=val)。您需要为此使用RewriteCond

    RewriteEngine on
    
    RewriteCond %{QUERY_STRING} ^topic=(.+)$ [NC]
    RewriteRule ^index.php$ http://newurl.com/index.php?topic=%1 [L,R,NE]
    

    【讨论】:

      猜你喜欢
      • 2017-12-17
      • 1970-01-01
      • 2012-05-12
      • 2016-09-15
      • 2017-06-12
      • 1970-01-01
      • 2014-09-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多