[.htaccess - Block / Banned IP] How to block access to a site for certain users… or for all but some.

Restricting access to a site for certain IPs, can be very simple .htaccess.

Order deny, allow
Deny from 191.155.1.30
Deny from 123.113.
Deny from 1.2.3.4  5.6.7.8 127.1.1.1
Allow from all 

If above the line "Order deny, allow"Says server order of priority. More specifically, access all IPs, except those that are listed in the lines "Deny from".

Deny from 191.155.1.30 - Blocks access to a single IP. In our example: 191.155.1.30

Deny from 123.113. - Block access all IPStarting with 123.113 sites.

For some versions of Apache, the above example would return 500 Internal Servers Error for all IPs accessing the site. If you experience this error, remove the lines above, the first and last line and use only:

Deny from 191.155.1.30
Deny from 123.113.
Deny from 1.2.3.4  5.6.7.8 127.1.1.1 

Like a reverse of the above statements is block all IPs, except for some.
Deny from all
Allow from 1.1.1.1
All IPs will have access blocked, less PC that has IP 1.1.1.1

Passionate about technology, I enjoy writing on StealthSettings.com since 2006. I have a rich experience in operating systems: macOS, Windows, and Linux, as well as in programming languages and blogging platforms (WordPress) and for online stores (WooCommerce, Magento, PrestaShop).

Leave a Comment