重定向到不同的URL与舱口类似参数舱口、重定向、类似、不同

2023-09-02 09:59:04 作者:絕版い少年ヾ

我想重定向以下字符串  productdetails.asp PID = 23&安​​培; CID = 1 要么 productdetails.asp PID = 23&安​​培; CID = 3 PID可以是任何号码,我有以下几点:

I want to redirect the following strings productdetails.asp?pid=23&cid=1 or productdetails.asp?pid=23&cid=3 pid could be any number I have the following:

RewriteCond %{QUERY_STRING} ^pid=([0-9]+)&cid=1?
RewriteRule ^productdetails.asp$ /Compare/Roland-Digital-Pianos? [L,NC,R=301]
RewriteCond %{QUERY_STRING} ^pid=([0-9]+)&cid=3?
RewriteRule ^productdetails.asp$ /Compare/Kawai-Digital-Pianos? [L,NC,R=301]

但由于某些原因,当CID = 3仍改写为/比较/罗兰数字,钢琴 同时,我希望它去比较/河合数字,钢琴 任何帮助欢迎

but for some reason when cid=3 it still rewrites to /Compare/Roland-Digital-Pianos while i want it to go to Compare/Kawai-Digital-Pianos Any help Welcome

推荐答案

这是因为放错位置的在重写条件。在正则表达式使previous组选它做 1 3 在您的查询字符串的选项。

That is because of misplaced ? in your rewrite condition. In regex ? makes previous group optional which is making 1 or 3 option in your query string.

使用这些规则来代替:

RewriteCond %{QUERY_STRING} ^pid=([0-9]+)&cid=1(&|$) [NC]
RewriteRule ^productdetails.asp$ /Compare/Roland-Digital-Pianos? [L,NC,R=301]
RewriteCond %{QUERY_STRING} ^pid=([0-9]+)&cid=3(&|$) [NC]
RewriteRule ^productdetails.asp$ /Compare/Kawai-Digital-Pianos? [L,NC,R=301]