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

时间:2013-04-03 20:37:49

标签: .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-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

我不希望在上面的网址末尾打印"?infoBox=5"

如何防止这种情况发生?

2 个答案:

答案 0 :(得分:2)

只需在目标网址上添加一个问号,如下所示:

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

网址中不能有两个问号,因此apache不会添加上一页的参数,因为新版本中已存在一个。

答案 1 :(得分:0)

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

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]