Sometimes, it becomes necessary to restrict access to a website, either for maintenance purposes or other specific reasons. However, there may still be a need to allow access to a single user or a specific IP address. In this guide, I will explain how to close the website to all users while granting access to only one IP address. This approach ensures the site remains secure and restricted during maintenance or troubleshooting while still allowing essential access for authorized personnel.
Step-by-Step Guide: Restricting Website Access to a Specific IP Address
First, Obtain Your IP Address
To start, you’ll need your IP address. [Click here for a guide on finding your IP address].
Access the Cpanel and File Manager
Once you have your IP, log in to your Cpanel and navigate to the File Manager.
Locate the Public Directory
Go to the public_html or htdocs folder, depending on whether you’re using a paid or free hosting service. Open the .htaccess
file within this folder.
Add the Restriction Code
In the .htaccess
file, add the following code to deny access to all users except for the specified IP:
Order Deny,Allow
deny from all
allow from 196.12.12.12
- Make sure to replace
196.12.12.12
with your actual IP address. - Save the Changes
Once you’ve added the code, click Save.
- Important Note
If you restart or reset your router, your IP address may change. Be sure to check and update the IP address in the.htaccess
file if this occurs to maintain access to the site.
Best of luck, and happy website maintenance!