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]
Related videos on Youtube
Author by
Tim D
Updated on September 18, 2022Comments
-
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 tomyclientdomain.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 about 10 yearsPresumably 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 about 10 yearsThe 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 about 10 yearsGot 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 about 10 yearsIf 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? IfHTTP_HOST
is working for you then I'd wager they have set upunwanteddomain.com
in DNS as anA
record that points tomyclientdomain.com
- but this is not a "redirect". -
Tim D about 10 yearsI 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 about 10 yearsIf this is a "redirect" (as in a 301 HTTP redirect) then the
HTTP_REFERER
won't be set tounwanteddomain.com
. TheHTTP_REFERER
will only be set in this case if the user was following a link fromunwanteddomain.com
. -
MrWhite about 10 yearsIs the
!
, preceding theRewriteCond
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, exceptunwanteddomain.com
!? -
Tim D about 10 yearsNo, corrected! My typo.