1. Home
  2. Hosting Management
  3. Troubleshooting
  4. How to Allow or Deny access to your website using .htaccess

How to Allow or Deny access to your website using .htaccess

.htaccess is a resourceful file that can allow or deny access to your website or a folder or files in the directory in which it is placed by using orderallow and deny keywords.

How to allow access to a single IP address using .htaccess

In the following example, we will assume that you want to allow access only to 1.2.3.4 IP address. The code that you will need to add in your .htaccess file is:

# Order Allow, Deny
Deny from All
Allow from 1.2.3.4

Order keyword here specifies the order in which allowdeny access would be processed. For the above ‘Order’ statement, the Allow statements would be processed first and then the deny statements would be processed.

How to deny access to a single IP Address using .htaccess

Let’s assume that you wish to deny or block access to your website from 1.2.3.4 IP address.

The below lines provide the means to allow access to your website from all users except one with the IP Address: 1.2.3.4

# Order Allow, Deny
Deny from 1.2.3.4
Deny from 1.2.3.5
Allow from All
# Order Deny, Allow
Deny from 1.2.3.4
Deny from 1.2.3.5

If there are multiple IP’s to which you want to deny access, simply add as many ‘Deny from’ rules as needed.

That’s it. Now you know how to Allow or Deny access to your website using .htaccess.

Looking for a new web host? We would be happy to help and even give a free trial period so it costs nothing to get started!

Updated on March 25, 2020

Was this article helpful?

Related Articles

Need help?
We're always here for you. Submit a ticket or Chat with a live person.
Submit Ticket

Leave a Comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.