0

All,

I am redirecting some urls with specific query strings to new page . For example http://testserver.xyz.com/abc/content/content.jsp?contentId=123 or http://testserver.xyz.com/abc/content/content.jsp?contentId=345 needs to be redirected to http://ww2.newtestserver.com/xyz.html

For this purpose i wrote following redirects:

RewriteCond %{QUERY_STRING} contentId=123 [OR]
RewriteCond %{QUERY_STRING} contentId=345 [OR] 
RewriteCond %{QUERY_STRING} contentId=678 
RewriteRule ^/(.*)$ http://ww2.newtestserver.com/xyz.html/? [R=301,L]

This works fine except when i type in my browser http://testserver.xyz.com/abc/content/content.jsp?contentId=1234. This also gets redirected to http://ww2.newtestserver.com/xyz.html.

I do not want this. how can i prevent this so that my mod rewrite only looks at query string 123 or 345 or 567 but not something 123x or 345x or 678x?

Please help

TIA

4

1 回答 1

0

To make sure that the rewrite looks only at the exact query strings you specified, you should tell it that those are the full query strings using ^ and $. ^ matches the beginning of the string, and $ matches the end.

RewriteCond %{QUERY_STRING} ^contentId=123$ [OR]
RewriteCond %{QUERY_STRING} ^contentId=345$ [OR]
RewriteCond %{QUERY_STRING} ^contentId=678$
RewriteRule ^/(.*)$ http://ww2.newtestserver.com/xyz.html [R=301,L]

The above code will work. The code below might work (and should be more efficient), but I'm not at a computer I can test on right now.

RewriteCond %{QUERY_STRING} ^contentId=(123|345|678)$
RewriteRule ^/(.*)$ http://ww2.newtestserver.com/xyz.html [R=301,L]
于 2012-10-27T07:26:50.400 回答