2

Due to marketing reasons, I'm using some vanity URL's for friendlier access, and to track some campaigns. Unfortunately, I'm stuck on a managed dedicated server, with cPanel, and these were the steps I took to write my rules:

  • First, I added xyz.com and efg.com to parked domains in my cPanel
  • Then I wrote all the RewriteRules that I needed

.htaccess

RewriteCond %{HTTP_HOST} ^xyz\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.xyz\.com$
RewriteRule ^signdirections$ "http\:\/\/xyz\.abc\.com\/en?utm_source=signdirections&utm_medium=advert&utm_campaign=xyz" [R=301,L]


RewriteCond %{HTTP_HOST} ^efg\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.efg\.com$
RewriteRule ^signdirections$ "http\:\/\/efg\.abc\.com\/en?utm_source=signdirections&utm_medium=advert&utm_campaign=efg" [R=301,L]

Now, the problem is that if I try to access www.efg.com/signdirections, I will get redirected to the www.xyz.com/signredirections version, instead of efg's one.

Any idea, why that is happening? My intuition, is that it detects the same hostname (HTTP_HOST), but I can't understand why.

anubhava
  • 761,203
  • 64
  • 569
  • 643
Alex
  • 7,538
  • 23
  • 84
  • 152
  • you have no other rules causing redirections? – hjpotter92 Nov 21 '14 at 11:47
  • @hjpotter92 there are more redirecting rules, but the clash is only where there are duplicated RewriteRules (ex: signdirections) on different hosts – Alex Nov 21 '14 at 14:46

2 Answers2

2

Most likely it is happening due to your other rules. Better to use THE_REQUEST variable that doesn't change after application of other rules.

You can also combine both your rules into one:

RewriteCond %{HTTP_HOST} ^(?:www\.)?(xyz|efg)\.com$ [NC]
RewriteCond %{THE_REQUEST} /signdirections [NC]
RewriteRule . http://%1.abc.com/en?utm_source=signdirections&utm_medium=advert&utm_campaign=%1 [R=301,L,NE,QSA]
  • Make sure this is your first rule below RewriteEngine On line.
  • Make sure to test it in a new browser to avoid old browser cache.
anubhava
  • 761,203
  • 64
  • 569
  • 643
0

I don't know, if that can be a cache error after a bad test:
How long do browsers cache HTTP 301s?

Just a simplified version:

RewriteCond %{HTTP_HOST} ^(?:www\.)?xyz\.com$
RewriteRule ^signdirections$ http://xyz.abc.com/en?utm_source=signdirections&utm_medium=advert&utm_campaign=xyz [R=302,L]

RewriteCond %{HTTP_HOST} ^(?:www\.)?efg\.com$
RewriteRule ^signdirections$ http://efg.abc.com/en?utm_source=signdirections&utm_medium=advert&utm_campaign=efg [R=302,L]

Try with R=302, and when everything works, change for R=301

Community
  • 1
  • 1
Croises
  • 18,570
  • 4
  • 30
  • 47