modernmagic
modernmagic

Reputation: 141

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]            

Upvotes: 1

Views: 118

Answers (1)

anubhava
anubhava

Reputation: 785471

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.

Upvotes: 2

Related Questions