简体   繁体   中英

How to not pass parameters in 301 redirect?

I want to redirect the following two links:

/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)

To:

yogicchaiDOTcom/rooibos-masala-chai-naturally-decaffeinated.html

I thought this was the solution:

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

But the end results is:

yogicchaiDOTcom/rooibos-masala-chai-naturally-decaffeinated.html?infoBox=5

I dont want the "?infoBox=5" printed at the end of the URL above

How can I prevent that from happening?

Simply add a question mark to the target URL like this:

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

There cannot be two question marks in an url, so apache will not add the parameters from the previous page, because there is already one in the new.

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM