1

I have done several attempts to figure out how to redirect visitors from the visitors hostname to some other place.

I know with IP this works:

RewriteCond %{REMOTE_ADDR} ^185\.93\.180\.* [OR]
RewriteCond %{REMOTE_ADDR} ^188\.143\.232\.31
RewriteRule ^(.*)$ attacker_reroute.php

But in this case, I need to do it by domain, any suggestions?

Something like

RewriteCond %{REMOTE_HOST} *\.badguys\.com
MrWhite
  • 12,647
  • 4
  • 29
  • 41

1 Answers1

0

The REMOTE_HOST server variable holds the resolved hostname of the remote IP address accessing the site. However, whether this contains the resolved hostname or not is dependent on HostnameLookups On being set in the server config. It is Off by default and many hosts disable this feature for performance reasons. This cannot be enabled in .htaccess.

If the HostnameLookups is not enabled then REMOTE_HOST simply contains the same as REMOTE_ADDR, ie. the IP address of the machine making the request.


Aside:

Be careful of your regex, you seem to be treating * like a "wildcard" character. In regex * is a quantifier meaning "0 or more of the preceding item".

^185\.93\.180\.*

This is matching "185.93.180." followed by any number of dots. It should be ^185\.93\.180 or ^185\.93\.180\. - just remove the *.

*\.badguys\.com

This is completely invalid. If you want to match any subdomain of "badguys.com" then you need the regex \.badguys\.com$ (basically remove the *). To match the domain apex or any subdomain then (^|\.)badguys\.com$.

MrWhite
  • 12,647
  • 4
  • 29
  • 41
  • Hello, Thanks for the info. Unfortunately its't taking this like an overall wildcard. I have This: RewriteCond %{REMOTE_HOST} ^|\.badguys\.com$
    RewriteCond %{REMOTE_HOST} ^|\.ip-51-255-209\.eu$
    RewriteRule ^(.*)$ https://GoSomwhere.com
    – user9604446 Apr 07 '21 at 02:57
  • @user9604446 Please edit your question to add your code. Comments are not for posting blocks of code - it's impossible to read as specific characters can get "lost" in the _unformatted_ text. In the code you posted, it looks like the parentheses are missing? What do you mean by "its't taking this like an overall wildcard"? (If the parentheses are really missing then yes, it will always redirect, if that's what you mean by "overall wildcard"?) Have you confirmed that `REMOTE_HOST` does contain the resolved hostname? – MrWhite Apr 07 '21 at 22:52