1

I need to add IP addresses to my .htaccess to allow access as shown in this question.

Only allow certain IP addresses to access site with mod_rewrite?

But I need to be able to add them as a range as I have some that span a great range and typing them out individually will take way too long. is there a way to express a range which will work with this format?

RewriteCond %{REMOTE_ADDR} !^XXX\.XXX\.XXX\.XXX
Joe
  • 4,877
  • 5
  • 30
  • 51
rushtoni88
  • 4,417
  • 7
  • 22
  • 31
  • Only by leaving of segments at the right, I suppose, because this is essentially string comparison. If you don’t need an actual rewrite to somewhere else, but just to allow or deny access, then check https://stackoverflow.com/questions/5042399/htaccess-access-to-file-by-ip-range – CBroe Jul 16 '18 at 09:46

1 Answers1

2

Yes, there is !

If you want to block a range of IPs then you can leave off the last octet of the IP address, for example:

RewriteCond %{REMOTE_ADDR} !^123\.123\.123

and you can shorten that even further if needed:

RewriteCond %{REMOTE_ADDR} !^123\.123

So for example, using the first option, you would be blocking the IP range of 123.123.123.1 - 123.123.123.255. So it covers the entire range.

This can also be achieved using the deny from rule in .htaccess.

Joe
  • 4,877
  • 5
  • 30
  • 51