301redirect自定义链接

我有几千这样的链接

/Gallery?cmd=viewCarGallery&carID=3747&pgID=1 

现在我想redirect他们使用.htaccess到另一个网站的其他链接。 每一个链接将被redirect到它自己的目标链接。 我试过这样

 Redirect 301 /Gallery?cmd=viewCarGallery&carID=3747&pgID=1 http://example.com/gallery/fcar_gallery 

但不工作。 我已经在我的服务器启用mod_rewrite和oltherredirect工作完美。

Querystring不是Redirect指令中匹配的一部分,为了redirect查询string,需要使用mod-rewrite,如下所示:

选项1

 RewriteEngine on RewriteCond %{THE_REQUEST} /Gallery\?cmd=viewCarGallery&carID=3747&pgID=1 [NC] RewriteRule ^ http://example.com/gallery/fcar_gallery? [NC,L,R] 

选项2

 RewriteEngine on RewriteCond %{QUERY_STRING} ^cmd=viewCarGallery&carID=3747&pgID=1 [NC] RewriteRule ^ http://example.com/gallery/fcar_gallery? [NC,L,R] 

我们使用一个空的问号 在目标url的末尾丢弃旧的查询string,否则这些查询string会默认被添加到目标url。

如果要使redirect永久化,请将R更改为R = 301

[在apache2和2.4上testing]