Redirecting to different url with similar parameters in hatches

我只是一个虾纸丫 提交于 2020-01-25 06:32:21

问题


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]

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


回答1:


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.

Use these rules instead:

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]


来源:https://stackoverflow.com/questions/26215599/redirecting-to-different-url-with-similar-parameters-in-hatches

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!