IP address access restriction is a useful feature to strengthen your website's security, prevent unauthorized access, or limit access to certain areas to specific users (office, developers, administrators, etc.).
This method allows you to, in particular:
Block unwanted visitors
Restrict access to a site or a folder
Prevent repeated attacks coming from a specific IP
Manage access without modifying the site's code
Prerequisites
Access to cPanel
Active hosting
Identify the IP address to allow or block
Task completion: 2 to 5 minutes
Expertise: beginner
How to do it?
Method 1 : Restrict access via the IP Blocker in cPanel (recommended)
This method is the simplest and does not require any manual file modifications.
Steps to follow:
Log in to your cPanel
In the Security section, click on IP Blocker
In the designated field, enter:
A full IP address (e.g. 192.168.1.10)
Or an IP range (e.g. 192.168.0.1-192.168.0.40)Click Add
The IP address is blocked immediately
The affected user will no longer be able to access your website.
Method 2 : Restrict access via the .htaccess file
This method is useful if you want to allow only certain IPs.
Steps to follow:
Log in to your cPanel
Open the File Manager
Go to the site folder (usually public_html)
Locate or create the .htaccess file
Add the following lines:
Order Deny,Allow
Deny from all
Allow from 123.123.123.123Replace 123.123.123.123 with the allowed IP address
Save the file
Important
⚠️ If you block all IPs except your own, make sure your IP address is correct, otherwise you risk losing access to your site.
⚠️ Changes made via .htaccess take effect immediately.
Références
Documentation cPanel – IP Blocker: <IP Blocker | cPanel & WHM Documentation >
