Skip to main content

Restricting IP access to a specific website page

Comments

9 comments

  • cPanelMichael
    Hello, Here are a couple of examples of how to do this from StackOverflow discussions: password protect a single file using .htaccess Password protecting a single page using .htaccess and .htpasswd Thank you.
    0
  • sawbuck
    What CMS? If Wordpress you could consider using a plugin: Restricted Site Access
    0
  • chanklish
    What CMS? If Wordpress you could consider using a plugin: Restricted Site Access

    no a CMS for a regular website not wordpress .. i want to IP restrict it
    0
  • rpvw
    In your htaccess file, you could try the following format:
    Order deny,allow Deny from all Allow from 127.0.0.1 Allow from 127.0.0.2
    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
    0
  • chanklish
    In your htaccess file, you could try the following format:
    Order deny,allow Deny from all Allow from 127.0.0.1 Allow from 127.0.0.2
    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
    0
  • rpvw
    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
    0
  • chanklish
    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

    worked perfectly ! thank you
    0
  • rpvw
    You are very welcome.
    0
  • chanklish
    hello again after all this time i was looking to deny access to a certain page except for my public ip i used the below in .htaccess but it is even blocking the ip address i am allowing - i am writing something wrong ? [CODE=php] Order deny,allow Deny from all Allow from 102.68.xx.xx
    0

Please sign in to leave a comment.