【问题标题】:Redirecting URL with parameters [duplicate]使用参数重定向 URL [重复]
【发布时间】:2021-01-02 04:29:48
【问题描述】:

我想重定向网址:

prolist.php?id=1297&lang=en 

到那个:

details.php?id=1297

但 id 不想重定向其他 URL 末尾没有“lang=en”参数的 URL。

【问题讨论】:

  • 所以你想实现一个RewriteCond 来匹配查询字符串的精确模式。

标签: apache .htaccess redirect mod-rewrite seo


【解决方案1】:

所以你想为你的重定向规则实现一个条件,它与查询字符串匹配一个精确的模式:

RewriteEngine on
RewriteCond %{QUERY_STRING} ^id=(\d+)&lang=en$
RewriteRule ^/?prolist\.php$ /details.php?id=%1 [QSD,R=301]

也许你还想实现一个内部重写规则:

RewriteEngine on

RewriteCond %{QUERY_STRING} ^id=(\d+)&lang=en$
RewriteRule ^/?prolist\.php$ /details.php?id=%1 [QSD,L,R=301]

RewriteCond %{QUERY_STRING} ^id=(\d+)$
RewriteRule ^/?details\.php$ /prolist.php?id=%1&lang=en [L]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-16
    • 2017-01-21
    • 2017-04-29
    • 1970-01-01
    • 2015-11-13
    • 1970-01-01
    • 2015-03-24
    • 2021-11-03
    相关资源
    最近更新 更多