Mod rewrite mod rewrite查询\u字符串问题

Mod rewrite mod rewrite查询\u字符串问题,mod-rewrite,apache2,Mod Rewrite,Apache2,全部, 我正在将一些带有特定查询字符串的URL重定向到新页面。例如http://testserver.xyz.com/abc/content/content.jsp?contentId=123或http://testserver.xyz.com/abc/content/content.jsp?contentId=345需要重定向到http://ww2.newtestserver.com/xyz.html 为此,我编写了以下重定向: RewriteCond %{QUERY_STRING} cont

全部,

我正在将一些带有特定查询字符串的URL重定向到新页面。例如
http://testserver.xyz.com/abc/content/content.jsp?contentId=123
http://testserver.xyz.com/abc/content/content.jsp?contentId=345
需要重定向到
http://ww2.newtestserver.com/xyz.html

为此,我编写了以下重定向:

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]
除了在浏览器中键入
http://testserver.xyz.com/abc/content/content.jsp?contentId=1234
。这也会被重定向到
http://ww2.newtestserver.com/xyz.html

我不要这个。如何防止这种情况发生,以便我的mod rewrite只查看查询字符串123、345或567,而不查看123x、345x或678x

请帮忙


TIA

为了确保重写只查看您指定的确切查询字符串,您应该使用
^
$
告诉它这些是完整的查询字符串
^
匹配字符串的开头,
$
匹配字符串的结尾

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]
上述代码将起作用。下面的代码可能会工作(并且应该更有效),但我现在不在一台可以测试的计算机上

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