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?

  • 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. – Jeremy Cook Mar 25 '14 at 22:34
  • 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. – Nicoli Mar 25 '14 at 22:44
  • 1
    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) – Nicoli Mar 25 '14 at 22:46
  • 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". – MrWhite Mar 26 '14 at 11:48
  • 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). – Nicoli Mar 26 '14 at 19:29

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.

  • 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!? – MrWhite Mar 26 '14 at 20:03
  • 1
    No, corrected! My typo. – Nicoli Mar 26 '14 at 21:23

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]
  • 3
    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 Mar 26 '14 at 11:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.