Question

I am new to .htaccess redirect.

I have a source URL with too many parameters query string.

Source

http://localhost/se/karriar/?utm_source=A_candy_box&utm_medium=Printed_media&
utm_term=2013&utm_content=Want_a_fresh_start_to_your_career%3F&
utm_campaign=Mint_pastille_campaign

Target: http://www.sample-website.com

When I tried to call source URL its getting redirected along with query string as like below.

http://www.sample-website.com?utm_source=A_candy_box&utm_medium=Printed_media&
utm_term=2013&utm_content=Want_a_fresh_start_to_your_career%3F&
utm_campaign=Mint_pastille_campaign

I have written the below script in .htaccess file.

RewriteCond %{HTTP_HOST} ^(www.)?localhost$ [NC]
RewriteCond %{QUERY_STRING} ^utm_source=A_candy_box&utm_medium=Printed_media&utm_term=2013&utm_content=Want_a_fresh_start_to_your_career%3F&utm_campaign=Mint_pastille_campaign$ [NC]
RewriteRule ^se/karriar(.*)$ http://www.sample-website.com [R=301,L,NC] `

I would like to not appending query strings in the targeted URL. Can you any one help me?

Was it helpful?

Solution

Replace your .htaccess with this

RewriteCond %{HTTP_HOST} ^(www.)?localhost$ [NC]
RewriteCond %{QUERY_STRING} ^utm_source=A_candy_box&utm_medium=Printed_media&utm_term=2013&utm_content=Want_a_fresh_start_to_your_career%3F&utm_campaign=Mint_pastille_campaign$ [NC]
RewriteRule ^se/karriar(.*)$ http://www.sample-website.com? [R=301,L,NC]

Append ? after your target domain.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top