首页 > 解决方案 > 使用参数重定向 URL

问题描述

我想重定向网址:

prolist.php?id=1297&lang=en 

对此:

details.php?id=1297

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

标签: apache.htaccessredirectmod-rewriteseo

解决方案


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

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]

推荐阅读