使用参数重定向 URL

Redirecting URL with parameters

我想重定向 URL:

prolist.php?id=1297&lang=en 

到那个:

details.php?id=1297

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

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

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]