Knowledge Base
MilesWeb / cPanel

Steps to block IP address with .htaccess

Approx. read time : 2 min

In this tutorial, we will learn how to deny an IP address or how to allow a particular IP address from accessing your website. This measure is taken to save the website from hackers or to block unwanted visitors.

First of all, you will need to create a .htacsess file in your public_html folder and add the following lines as per the requirements:

1) Code to deny a specific IP address –

Deny from 192.0.5.1

This code will deny one IP address from accessing your website. Make sure you use the IP address for which you wish to work.

2) Code to deny specific domain –

Deny from 192.0.0.1/366.366.366.0

Using this code you can deny a specific domain from accessing your domain. Use the code in .htaccess file, and replace IP address and netmask value to match the domain that you wish to block.

3) Code to deny multiple IP’s in a single line of code –

While using this code, leave a blank space with each IP for separation.

Deny from 111.111.111.111 444.444.444.444 666.666.666.666

Replace IPs of your choice in .htaccess file.

4) Code to allow only a single IP –

The below code will deny access of all the other websites from every IP address except the IP address mentioned in the rule :

Order Deny,Allow
Deny from all
Allow from 222.222.222.222

This code indicates that first, we have denied all visitors and then allowed only the visitor from a specified IP address.

5) Code to deny single IPv6 address –

Use the following code to block IPv6 address through .htaccess file :

Deny from 2001:cdba:0000:0000:0000:0000:3284:7536

That’s it!

Also Read :

1) Learn to Block A User Agent in An .htaccess File

2) What Are The Common Reasons For A Website To Be Inaccessible?

With an interest in doing something creative daily, Sonam works as a Digital Marketing Executive. She likes to write technical blogs related to web hosting, digital marketing, and other IT topics. She also likes to spend her leisure time on social media to find different strategies for client engagement.

Trusted By Thousands of Clients & Big Businesses

We highly appreciate the kind and stellar feedback we receive from our customers. Delivering the best is our goal! MilesWeb is rated Excellent out of 5 based on reviews. Read more reviews.

Excellent
Based on reviews
2 hours ago
Perfect and Valuable Server + ...
I am using MilesWeb Servers, The main thing which I getting are continuous support over everything w...
Gunjan Makwana
4 hours ago
Milesweb is superb Hosting pro...
Milesweb is superb Hosting provider ever, their Support team is amazing!!!...
Abhishek Singh
15 hours ago
Great support in great timing...
We need urgent assistance on changes in a primary domain on our client's Cpanel accounts and reached...
Riyaju Deen
21 hours ago
Best Website Hosting platform ...
I was new on MilesWeb. And needed help on multiple areas from setting up to getting started with cre...
Harshada
1 days ago
Very quick and helpful assista...
Very quick and helpful assistance. Support person listened properly and provided a nice solution....
Narendra
1 days ago
the team is very supportive th...
the team is very supportive though at times effort needs to be made to make understand the problem s...
Suree Sharma
1 days ago
I am using miles web for 3plus...
I am using miles web for 3plus years, very quick and perfect support by the team, they helped me man...
Sri Raghav
2 days ago
The service is good...
The service is good. They are answering with patience and doing the needful as soon as possible....
MR
2 days ago
Perfect and Valuable Server + ...
I am using MilesWeb Servers, The main thing which I getting are continuous support over everything w...
Gunjan Makwana
3 days ago
Very quick and helpful assista...
Very quick and helpful assistance. Support person listened properly and provided a nice solution....
Narendra
4 days ago
positively helped me with find...
positively helped me with finding insecure content on my website causing SSL to not work properly on...
Thaviraj Junglee
4 days ago
Exceptional support, Truly Pra...
I had opted for the basic wordpress hosting plan as I intended to experiment with various plug-ins. ...
Aseem Chandna