How to Block an IP Address using .htaccess?

You can block traffic from any specific IP address with the .htaccess file by following the steps listed below –

1. Log in to your cPanel account and open the File Manager.

file manager

2. Open the public_html directory.

3. Click on Setting, tick the Show Hidden Files (dotfiles) option, and then click Save.

show hidden files

4. Right-click on the .htaccess file and click on the Edit option.

5. Insert the following lines in the .htaccess file as shown in the screen capture, and save the file.

Order Deny, Allow
Deny from

Replace the IP with the actual IP Address you want to block for your website.

Was this answer helpful?

« Back