Restricting User Access by an IP Address

Task:

I want to block access to my web space to only on-campus computers or to a specific IP Address.

How to do it:

Below are three different ways to block IP Addresses using a .htaccess file.

Follow these steps:

  1. Open a text editor, like Notepad, and enter the text from one of the following three steps.

  2. To restrict to on-campus computers only:
    <Limit GET POST PUT>
    order deny,allow
    deny from all
    allow from 131.204.
    </Limit>
    ErrorDocument 403 /home/path/user name/public_html/errorpage.html
    Create an errorpage.html that tells outside users that they are blocked with an explanation.

  3. To restrict a specific IP Address:
    <Limit GET POST PUT>
    deny from all 123.123.12.123
    </Limit>
    Change the IP Address to the one you would like to block.

     

  4. To restrict by certain domains or passwords:
    AuthUserFile /home/path/user name/public_html/.htpasswd
    AuthGroupFile /home/path/user name/public_html/.htgroup
    AuthName Friend
    AuthType Basic

    <Limit GET POST PUT>
    order deny,allow
    deny from all
    allow from 131.204
    require group mystudents
    satisfy any
    </Limit>

    Use satisfy all to restrict by domains and passwords. See the password protected pages tutorial for information.

     

  5. Save the file as .htaccess and upload to the directory that you would like to restrict access to using FTP.

How-to: Password protecting your pages