Using htaccess File to Block IPs

If your webserver is Apache, you may block access to your website from specific IP addresses using .htaccess file.

You need to create this file in your document root folder and add these example lines:

order allow,deny
deny from 127.0.0.1
allow from all

These lines will block access for all users using 127.0.0.1 IP address.

If you need to block a group of IP addresses. use these example lines:

order allow,deny
deny from 127.0.0.1/24
allow from all

These lines will block access for all IP addresses within the 127.0.0.1/24 subnet. This should be in CIDR notation.

  • apache, block ips
  • 106 Users Found This Useful
Was this answer helpful?

Related Articles

How to Create Sudo User on CentOS

This article provides step-by-step setup guide for adding Sudo user to CentOS system. The sudo...

How to Use Sudo

This article provides a guide to using a Sudo user on CentOS server. From the command line,...

Set Server Time Zones with Timedatectl

This article provides a guide to setting the server time and server time zone settings using...

htaccess RewriteRule Examples

Here are some useful mod_rewrite RewriteRule redirect examples that you can use in your .htaccess...

Enable Browser Caching with htaccess File

Enable browser caching to reduce website loading times, by taking advantage of caching of...