CodeSteps

Python, C, C++, C#, PowerShell, Android, Visual C++, Java ...

How to allow or deny website access to particular IP address using .htaccess file?

The .htaccess file or hypertext access file is directory level configuration file supported by several web servers to provide access control. A .htaccess file is often used to specify for authorization, authentication, rewriting URLs, blocking, customized error responses etc.,.

As mentioned above we can use .htaccess file to allow or deny access the resources. This article explains the steps to allow the website access only to particular IP address.

Step (1). Open your website’s .htaccess file in code editor. This file will be located in the root folder where you installed your website.

Step (2). Go to end of the file and paste the following code:

<limit GET POST>
order deny,allow
deny from all
allow from <<here provide public IP address of the machine allowed to access the website>>
</limit>

Here we used <limit> directive to restrict GET and PUT http methods access. And allow to only particular IP address. If you want to deny access to only particular IP address and allow the access to every one the code should be like this:

<limit GET POST>
order allow,deny
allow from all
deny from <<here provide public IP address of the machine denied to access the website>>
</limit>

Step (3). Once you done with the changes, save your changes into .htaccess file and close the code editor window.

Step (4). Refresh your website. You will find that your website will be accessible to only the particular machine whose IP address is matched with the mentioned IP address in .htaccess file. If you try to access the website from other machines, it will show the error message.

by Code Steps

 

How to allow or deny website access to particular IP address using .htaccess file?

One thought on “How to allow or deny website access to particular IP address using .htaccess file?

  1. Pingback: My Homepage

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top