.htaccess 重定向错误与查询字符串更改

.htaccess redirect error with query string change

我有一个 URL 是:

http://example.com?country=uk&animal=dog&size=large

我希望将查询字符串更改为

http://example.com?country=uk&animal=cat&size=small

我已经在 .htaccess 测试器中试过了

Options +FollowSymlinks
RewriteEngine on

RewriteCond %{QUERY_STRING} ^(.*[&?]|)animal=(dog)&size=(large)([&?].*|)$
RewriteRule ^(.*)$ ?%1animal=cat&size=small[R=301,NC,L]

但是重写中的 & 不断显示 686 !

http://example.com?country=uk&animal=cat686size=small

如有任何想法,我们将不胜感激。

使用您显示的示例,请尝试遵循 htaccess 规则。请确保在测试您的 URL 之前清除您的浏览器缓存。

##making engine one here.
RewriteEngine ON
##External redirect rule goes here. Please make sure to use correct back references to be used later on.
RewriteCond %{THE_REQUEST} \s/([^?]*)\?(country=)uk&(animal=)dog(&size=)large [NC]
##Applying redirection with 301 redirect here.
RewriteRule ^ /%1?%2uk&%3cat&%4small [R=301,L]