.htaccess, how to block a specific IP address from accessing your website

How to block a specific IP address from accessing your website

You just have to create a file called .htaccess and place it in the www folder (or in a particular directory that you wish to restrict access to).

To deny access

This file should contain the deny rules. Each rule is specified on a line as follows:

deny from IP_address
or deny from IP_block
or deny from domain

Then all you have to do is replace the generic term with the element that you wish to block. Here are some examples:

  • If you want to block the 192.168.1.2 IP address, you type:
deny from 192.168.1.2
  • If you want to block all the 192.168.x.x IP addresses, you type:
deny from 192.168
  • If you wanted to block all the IPs with a Wanadoo ID (this is just an example...), you would type:
deny from .wanadoo.com

To allow

In order to allow certain IPs, you should replace deny with allow (compared to the examples above)

Example: If you want to allow the 192.168.1.2 IP address, you type:

order deny,allow
deny from all
allow from 192.168.1.2

However, you cannot allow an incomplete IP block, in other words you can enter:

order deny,allow
deny from all
allow from 192.168.1

This will work, but if you enter the following you will get a 500 error, for example:

order deny,allow
deny from all
allow from 192.168

Go further

Join our community of users on https://community.ovh.com/en/.


Did you find this guide useful?

Please feel free to give any suggestions in order to improve this documentation.

Whether your feedback is about images, content, or structure, please share it, so that we can improve it together.

Your support requests will not be processed via this form. To do this, please use the "Create a ticket" form.

Thank you. Your feedback has been received.


These guides might also interest you...

OVHcloud Community

Access your community space. Ask questions, search for information, post content, and interact with other OVHcloud Community members.

Discuss with the OVHcloud community