.htaccess 如何在301重定向中不传递参数?

.htaccess 如何在301重定向中不传递参数?,.htaccess,redirect,http-status-code-301,.htaccess,Redirect,Http Status Code 301,我想重定向以下两个链接: /catalog/yogicchai/rooibos-masala-chai-naturally-caffeine-c-84.html?infoBox=5 (category link) /catalog/yogicchai/rooibos-masala-chai-naturally-decaffeinated-p-291.html (product link) 至: yogicchaiDOTcom/rooibos-masala-chai-naturally-de

我想重定向以下两个链接:

/catalog/yogicchai/rooibos-masala-chai-naturally-caffeine-c-84.html?infoBox=5 (category link)


/catalog/yogicchai/rooibos-masala-chai-naturally-decaffeinated-p-291.html (product link)
至:

yogicchaiDOTcom/rooibos-masala-chai-naturally-decaffeinated.html
我认为这就是解决办法:

RedirectMatch 301 /catalog/yogicchai/rooibos-masala-chai(.*)\.html 
yogicchaiDOTcom/rooibos-masala-chai-naturally-decaffeinated.html
但最终结果是:

yogicchaiDOTcom/rooibos-masala-chai-naturally-decaffeinated.html?infoBox=5
我不想在上面的URL末尾打印
“?infoBox=5”


如何防止这种情况发生?

通过
httpd.conf
启用mod_rewrite和.htaccess,然后将此代码放在
文档根目录下的
.htaccess
中:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^catalog/yogicchai/rooibos-masala-chai.*?\.html$ /rooibos-masala-chai-naturally-decaffeinated.html? [L,R=301,NC]

只需向目标URL添加问号,如下所示:

RedirectMatch 301 /catalog/yogicchai/rooibos-masala-chai(.*)\.html 
yogicchaiDOTcom/rooibos-masala-chai-naturally-decaffeinated.html?

url中不能有两个问号,因此apache不会添加上一页中的参数,因为新页面中已经有一个参数。

谢谢Anubhava。不幸的是,我仍然看到?infoBox=5打印在url的末尾:(
在目标URL末尾去掉查询参数。顺便问一句,它是否被重定向到
/rooibos masala chai自然去除咖啡因。html
?还要确保清除浏览器缓存并重新启动浏览器。是的,在清除缓存后,它会去掉所有查询参数,但现在URL以?有什么办法修复吗?谢谢s!即使是问号也不应该出现。因为
最后只用于剥离查询参数。根据您的重写规则,您将url重定向到以结尾?这是正确的还是错误的?