1

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?

4
  • You have not specify what you are expecting? Commented Mar 28, 2014 at 11:14
  • +2 for prompting it. I have edited my question. Commented Mar 28, 2014 at 11:19
  • Are you expecting this http://www.sample-website.com only when being redirected from localhost? Commented Mar 28, 2014 at 11:24
  • @RahilWazir yes you are right. (note: i mentioned localhost for example only i will replace the localhost with my company domain name) Commented Mar 28, 2014 at 11:28

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Bravo! its working. That ? question mark was missing. Thanks a lot.
Hi All, a little more help will be very helpful. The "%3F" characters are creating problem in this URL redirection. I tested that by removing that "%3F" characters and laso changing that to question mark (?) symbol etc... Any help will be highly appreciated.
@user26258 Create a new instance of this question please.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.