简体   繁体   中英

Redirect specific urls from old domain to new domain and retain parameters

Here is a sample old URL: https://www.olddomain.com/index.php?option=com_k2&view=itemlist&task=calendar&month=8&year=1904&catid=39&Itemid=339

Which needs to be redirected to: https://www.newdomain.com/index.php?option=com_k2&view=itemlist&task=calendar&month=8&year=1904&catid=39&Itemid=339

Since there are countless month,year,catid,and itemid I wanted to catch them all with one rule.

I was trying to create a htaccess redirect for any URL that has "/index.php?option=com_k2&view=itemlist&task=calendar" .

This was my best attempt:

RewriteEngine on
RewriteRule ^/index.php?option=com_k2&view=itemlist&task=calendar(.*)$ https://www.newdomain.com/index.php?option=com_k2&view=itemlist&task=calendar$1 [R=301,L]            

You may be able to use this redirect rule:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^(?:www\.)?olddomain\.com$ [NC]
RewriteCond %{QUERY_STRING} ^option=com_k2&view=itemlist&task=calendar [NC]
RewriteRule ^ https://newdomain.com%{REQUEST_URI} [R=301,L,NE]

Make sure this your topmost rule and you refresh your browser cache before testing this rule.

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