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:
- Open a text editor, like Notepad, and enter the text from one of the following three steps.
- To restrict to on-campus computers only:
<Limit GET POST PUT>
Create an errorpage.html that tells outside users that they are blocked with an explanation.
order deny,allow
deny from all
allow from 131.204.
</Limit>
ErrorDocument 403 /home/path/user name/public_html/errorpage.html
- To restrict a specific IP Address:
<Limit GET POST PUT>
Change the IP Address to the one you would like to block.
deny from all 123.123.12.123
</Limit> - To restrict by certain domains or passwords:
AuthUserFile /home/path/user name/public_html/.htpasswd
Use satisfy all to restrict by domains and passwords. See the password protected pages tutorial for information.
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> - 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
