String Htaccess重写单个查询字符串

String Htaccess重写单个查询字符串,string,.htaccess,mod-rewrite,String,.htaccess,Mod Rewrite,我和一个相当老的siye有点问题。我有一些带有查询字符串的通用URL,我想301重定向,但我不想重新定向URL。我想选择每个查询字符串被重定向的位置,因为站点中有很多不同的类别。例如: 我想改变: index.php?_a=viewCat&catId=199 致: 但是我想将另一个catid更改为我选择的另一个URL,完全不同的结构。我遇到的问题是,如果我没有?在目标url的末尾,它可以工作,但会将查询字符串附加到末尾,如果我将其放在末尾,它根本不会重定向 我正在使用的代码: Rewr

我和一个相当老的siye有点问题。我有一些带有查询字符串的通用URL,我想301重定向,但我不想重新定向URL。我想选择每个查询字符串被重定向的位置,因为站点中有很多不同的类别。例如:

我想改变:

index.php?_a=viewCat&catId=199
致:

但是我想将另一个catid更改为我选择的另一个URL,完全不同的结构。我遇到的问题是,如果我没有?在目标url的末尾,它可以工作,但会将查询字符串附加到末尾,如果我将其放在末尾,它根本不会重定向

我正在使用的代码:

RewriteCond %{QUERY_STRING} ^_a=viewCat&catId=199 
RewriteRule ^index\.php$  /garden-furniture/patio-furniture/garden-benches-garden-seats/cat_199.html? [L,R=301]
任何帮助都将不胜感激

编辑:我的htaccess的其余部分

RewriteEngine On
RewriteRule ^conservatory/(.*)$ /conservatory-furniture/$1 [R=301,L]
RewriteRule ^dining-room/(.*)$ /dining-room-furniture/$1 [R=301,L]
RewriteRule ^garden/(.*)$ /garden-furniture/patio-furniture/$1 [R=301,L]



RewriteBase /
RewriteCond %{QUERY_STRING} (.*)$
 RewriteRule cat_([0-9]+)(\.[a-z]{3,4})?(.*)$   index.php?_a=viewCat&catId=$1&%1 [NC]

RewriteCond %{QUERY_STRING} (.*)$
RewriteRule prod_([0-9]+)(\.[a-z]{3,4})?$   index.php?_a=viewProd&productId=$1&%1 [NC]

RewriteCond %{QUERY_STRING} (.*)$
RewriteRule info_([0-9]+)(\.[a-z]{3,4})?$   index.php?_a=viewDoc&docId=$1&%1 [NC]

RewriteCond %{QUERY_STRING} (.*)$
RewriteRule tell_([0-9]+)(\.[a-z]{3,4})?$   index.php?_a=tellafriend&productId=$1&%1 [NC]

RewriteCond %{QUERY_STRING} (.*)$
RewriteRule _saleItems(\.[a-z]+)?(\?.*)?$   index.php?_a=viewCat&catId=saleItems&%1 [NC,L]

如果这些是完整的URL,则可以在字符串开头锚定模式

RewriteRule ^cat_([0-9]+)(\.[a-z]{3,4})?(.*)$   index.php?_a=viewCat&catId=$1&%1 [NC]
这将防止将内部有
cat_quot
的URL重写为
index.php?..

由于您不使用尾随可选部分,因此也可以删除此部分

RewriteRule ^cat_([0-9]+) index.php?_a=viewCat&catId=$1&%1 [NC]
另一点是带有查询字符串的
RewriteCond
。如果查询字符串是可选的,则可以删除
RewriteCond
,并将
RewriteRule
修改为

RewriteRule ^cat_([0-9]+) index.php?_a=viewCat&catId=$1 [QSA,NC]
因此,所有这些都将成为

RewriteRule ^cat_([0-9]+) index.php?_a=viewCat&catId=$1 [QSA,NC]
RewriteRule ^prod_([0-9]+) index.php?_a=viewProd&productId=$1 [QSA,NC]
RewriteRule ^info_([0-9]+) index.php?_a=viewDoc&docId=$1 [QSA,NC]
RewriteRule ^tell_([0-9]+) index.php?_a=tellafriend&productId=$1 [QSA,NC]
RewriteRule ^_saleItems index.php?_a=viewCat&catId=saleItems [QSA,NC,L]

无论是否重写查询字符串,重定向都应该有效。当您在替换的末尾添加问号时,会发生什么情况?你还有其他规定吗?如果我把?最后,链接在重定向时中断。说它不能显示页面(所以我假设查询字符串没有被发送,所以没有要生成的页面?)我有一些其他规则,它们只是创建我重定向到的友好URL。我猜,与相应的其他规则一起,你有一个无止境的循环。也许这另一个答案有帮助,我尝试了本文中列出的规则,但也没有任何帮助-不确定是什么原因造成的-因为最后带有问号的重定向确实有效,它会将其发送到正确的位置。它只是不产生一个工作页面——这是因为一个无休止的循环吗?正如我所说,问号不应该改变任何东西。一定有其他规则或指令导致了这种情况。只要你不显示其他规则,这只是猜测。很抱歉延迟回复你。这些改变完全破坏了网站。一切都变成了404错误。
RewriteRule ^cat_([0-9]+) index.php?_a=viewCat&catId=$1 [QSA,NC]
RewriteRule ^prod_([0-9]+) index.php?_a=viewProd&productId=$1 [QSA,NC]
RewriteRule ^info_([0-9]+) index.php?_a=viewDoc&docId=$1 [QSA,NC]
RewriteRule ^tell_([0-9]+) index.php?_a=tellafriend&productId=$1 [QSA,NC]
RewriteRule ^_saleItems index.php?_a=viewCat&catId=saleItems [QSA,NC,L]