This tutorial will explain how to deny an IP address or how to allow only a particular IP address to access your website. This is extremely useful to protect your website from hackers or to block unwanted visitors.
You need to create an .htaccess file in your public_html folder and add these lines below, based on your requirements.
To Deny a Specific IP Address
The below code will only deny one IP address from accessing the website.
Deny from 192.0.0.1
Just change the IP address to the IP address that you want to deny and paste it in the .htaccess file.
To Deny a Specific Domain
We can deny a specific domain from accessing our domains by adding the below line of code to your .htaccess file.
Deny from 192.0.0.1/255.255.255.0
You need to change the IP address and netmask value to match the domain that you want to block.
To Deny Multiple IP’s in a Single Line of Code
Leave a blank space with each IP for separation.
Deny from 184.108.40.206 220.127.116.11 333.333.333.333
All you need to do is replace the IPs that you want to deny and paste it in the .htaccess file.
To Allow Only a Single IP
The below set of .htaccess rule will deny access to the website from every IP address expect the IP address mentioned in the rule.
Order Deny,Allow Deny from all Allow from 18.104.22.168
Here we first deny all visitors, and then allow only the visitor from the IP address specified above.
To Deny a Single IPv6 Address
To block a IPV6 address via .htaccess, follow the syntax below:
Deny from 2001:cdba:0000:0000:0000:0000:3257:9652
Now, when a user tries to visit your site from a blocked IP address, they would see a 403 Forbidden page instead.
If the steps above listed in this article do not resolve your issue, please feel free to open a support ticket and we’d be happy to take a look.
Ready for NVMe Hosting? And you thought SSD was fast...Get started today for $1.00 Promo code: 1dollar
Our Guiding Principles
- Provide consistent, stable and reliable web hosting services.
- Ensure rapid ticket response and quick resolutions to issues.
- Never saturate or over-provision servers to ensure stability and speed for our customers.
- Use only high quality enterprise-class hardware to ensure minimal downtime from hardware failures.
- Provide clear pricing with no hidden fees or gotchas.