Unwanted redirect from a domain to my site

14,321

Solution 1

Finally resolved using these rewrite rules:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.unwanteddomain.com$ [NC]
RewriteRule .* http://whateverPlaceYouWantToSend.com [R,L]

HTTP_REFERER did not work so I used HTTP_HOST.

Solution 2

The way I would do this is block all requests which are coming from unwantedcomain.com by checking for HTTP_REFERER

  • Block traffic from a single domain:

    RewriteEngine on
    RewriteCond %{HTTP_REFERER} unwateddomain\.com [NC]
    RewriteRule .* - [F]
    
  • Block traffic from multiple domains:

    RewriteEngine on
    RewriteCond %{HTTP_REFERER} unwanteddomain\.com [NC,OR]
    RewriteCond %{HTTP_REFERER} anotherdomain\.com
    RewriteRule .* - [F]
    
Share:
14,321

Related videos on Youtube

Tim D
Author by

Tim D

Updated on September 18, 2022

Comments

  • Tim D
    Tim D over 1 year

    An external person from my client company registered a domain and redirected to my client URL.

    For instance, if you type unwanteddomain.com it redirects to myclientdomain.com.

    Is there any way to block or redirect (for second time) to nowhere the unwanteddomain.com via cPanel or any rewrite rules on .htaccess?

    • Jeremy Cook
      Jeremy Cook about 10 years
      Presumably you cannot contact or work with the external person. I would work with your host and request that they configure the web server to only accept requests for myclientdomain.com and www.myclientdomain.com. I did this recently with my host, although that was with IIS.
    • Tim D
      Tim D about 10 years
      The unwanted domain is the name of another company that has good relations with my client but they do not want to be redirected to my clients. Obviously a claim is in the works, meanwhile I must block the redirect.
    • Tim D
      Tim D about 10 years
      Got a solution using RewriteCond %{HTTP_HOST} !^www.unwanteddomain.com$ [NC] I will post bellow once I can (Because I am new to PW I must wait 8 hours to answer my own question)
    • MrWhite
      MrWhite about 10 years
      If this is a "normal" 301 HTTP redirect, which would seem to be implied, then it's difficult to see how a solution using HTTP_HOST would work? If HTTP_HOST is working for you then I'd wager they have set up unwanteddomain.com in DNS as an A record that points to myclientdomain.com - but this is not a "redirect".
    • Tim D
      Tim D about 10 years
      I checked the A record, it does not point to my client IP. Using HTTP_REFERER just blocked the full site (maybe I applied the rule the wrong way).
  • MrWhite
    MrWhite about 10 years
    If this is a "redirect" (as in a 301 HTTP redirect) then the HTTP_REFERER won't be set to unwanteddomain.com. The HTTP_REFERER will only be set in this case if the user was following a link from unwanteddomain.com.
  • MrWhite
    MrWhite about 10 years
    Is the !, preceding the RewriteCond pattern, intentional? Otherwise this appears to do the complete opposite of what you are trying to achieve in the question and redirects every other domain, except unwanteddomain.com!?
  • Tim D
    Tim D about 10 years
    No, corrected! My typo.