重定向到不同的URL与舱口类似参数 [英] Redirecting to different url with similar parameters in hatches

查看:108
本文介绍了重定向到不同的URL与舱口类似参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重定向以下字符串  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]

这篇关于重定向到不同的URL与舱口类似参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆