Mobile app version of vmapp.org
Login or Join
Sue5673885

: Apache - .httaccess RewriteRule from domainA to domainB Problem: I have a website (mywebsite.com) that was, and partly is, indexed in google. Somebody pointed their own domain (theirsite.com) name

@Sue5673885

Posted in: #Apache

Problem:

I have a website (mywebsite.com) that was, and partly is, indexed in google. Somebody pointed their own domain (theirsite.com) name to my server and DNS, so it resolves with my IP. Now, probably being an older domain, it outranks me in google, and the pages at my domain are starting to getting de-indexed (probably duplicate content or something).
So, for example, my homepage got de-indexed, and their homepage (theirsite.com/) is indexed with my content/code/etc. The same is for other pages (theirsite.com/other/page.html is showing mysite.com/other/page.html)

Quick-fix:
To quickly fix it, I have added few lines to my PHP code, checking for $_SERVER['HTTP_HOST'], and if different than my domain, redirects to my domain.
It does the job, but to me it looks like a dirty solution.

Question:
I could not find a way to have apache to do this job. I would prefer to find an apache/.htaccess solution to this problem (redirecting all traffic from domainA.com/(.*) to domainB.com/), is it possible in any way?

Thanks

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Sue5673885

1 Comments

Sorted by latest first Latest Oldest Best

 

@Sent6035632

Your problem looks very similar to preventing hotlinking. There are many tutorials explaining how to do that (here's a random one from Google results), I'd suggest checking them first. They usually are concerned with the referer though, so you'd need to adapt the solution for your case (I believe it's just a matter of replacing HTTP_REFERER with HTTP_HOST). I wish I could help more with the details, but I'm unfamiliar with the workings of mod_rewrite.

In a nutshell, what you need to do for a "proper" solution would be:


Create a RewriteCond to match requests from theirsite.com;
Create a RewriteRule to do something with those requests (I believe a 410 Gone would be the right action).


Update: after seeing some examples, I believe I was able to get the code right:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^http://(.+.)?mysite.com/ [NC]
RewriteRule .*$ - [G]


That would rewrite any request where the HTTP_HOST is not your own site, sending a 410 Gone as the response.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme