Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 重写规则-匹配带或不带查询字符串的精确URL_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Apache 重写规则-匹配带或不带查询字符串的精确URL

Apache 重写规则-匹配带或不带查询字符串的精确URL,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,我有一个旧URL列表,这些URL被映射到它们对应的新URL。有些旧的URL包含查询字符串,有些则不包含 映射没有设置模式,所以我不能使用任何通配符规则,我需要进行精确匹配 我一直在尝试这种方法: RewriteRule ^products/index\.cfm\?pageName=Products/Index$ /test1/ [R=301,QSD,L,NC] RewriteRule ^products/index\.cfm$ /test2/ [R=301,QSD,L,NC] 但是,如果我转到

我有一个旧URL列表,这些URL被映射到它们对应的新URL。有些旧的URL包含查询字符串,有些则不包含

映射没有设置模式,所以我不能使用任何通配符规则,我需要进行精确匹配

我一直在尝试这种方法:

RewriteRule ^products/index\.cfm\?pageName=Products/Index$ /test1/ [R=301,QSD,L,NC]
RewriteRule ^products/index\.cfm$ /test2/ [R=301,QSD,L,NC]
但是,如果我转到,它将在第二条规则中匹配,并重定向到

谢谢


JT

您无法在重写规则的模式中匹配查询字符串。您需要匹配
%{QUERY\u STRING}
变量:

RewriteCond %{QUERY_STRING} ^pageName=Products/Index$ [NC]
RewriteRule ^products/index\.cfm$ /test1/ [R=301,L,NC]

RewriteCond %{QUERY_STRING} ^$ [NC]
RewriteRule ^products/index\.cfm$ /test2/ [R=301,L,NC]

谢谢你,乔恩,很好用。对于使用此解决方案的任何人,添加QSD标志将停止将查询字符串附加到新URL的末尾。