SOLVED Restricting IP access to a specific website page

chanklish

Well-Known Member
May 22, 2015
63
0
6
kinshasa
cPanel Access Level
Root Administrator
hello awesome people of cpanel
i am looking to restrict access to a specific page in my website to a number of ip addresses
i already looked into blocking ip option in cpanel or in htaccess but this will block the entire website - i just want to restrict a single page per example the CMS login page
is this doable on whm/cpanel ?!
thank you
 

rpvw

Well-Known Member
Jul 18, 2013
1,088
446
113
Spain
cPanel Access Level
Root Administrator
In your htaccess file, you could try the following format:
Code:
   <Files file.ext>
       Order deny,allow
       Deny from all
       Allow from 127.0.0.1
       Allow from 127.0.0.2
   </Files>
where file.ext is the file you want to restrict the access to, and 127.0.0.1, 127.0.0.2 etc are the IPs you want to allow access to that file (add as many as you need)

If the file you are trying to protect is in a sub-folder, you might need to create an additional htaccess file with the above code in the folder that contains the file
 
  • Like
Reactions: chanklish

chanklish

Well-Known Member
May 22, 2015
63
0
6
kinshasa
cPanel Access Level
Root Administrator
In your htaccess file, you could try the following format:
Code:
   <Files file.ext>
       Order deny,allow
       Deny from all
       Allow from 127.0.0.1
       Allow from 127.0.0.2
   </Files>
where file.ext is the file you want to restrict the access to, and 127.0.0.1, 127.0.0.2 etc are the IPs you want to allow access to that file (add as many as you need)

If the file you are trying to protect is in a sub-folder, you might need to create an additional htaccess file with the above code in the folder that contains the file
the page im looking to restrict is something like this : example.com/admin/login.php so the page is login.php ..
how do i know if i need another htaccess ? this login.php is inside /public_html/admin and the htaccess is in public_html
 
Last edited by a moderator:

rpvw

Well-Known Member
Jul 18, 2013
1,088
446
113
Spain
cPanel Access Level
Root Administrator
Add a new .htaccess file into the folder /admin with the code above, replacing the 'file.ext' with login.php and changing the IPs as required
 
  • Like
Reactions: chanklish

rpvw

Well-Known Member
Jul 18, 2013
1,088
446
113
Spain
cPanel Access Level
Root Administrator
You are very welcome.