How to block access to your website
Posted: Sun Nov 29, 2009 3:35 am
To block an IP address or a domain name from accessing your website, put these lines in your .htaccess file.
You can specify a partial IP address (just the first three sets of numbers, for example) if you want to block a range of addresses.
You can also use a partial domain name.
Note that blocking by domain name depends on the browser sending the referrer code, which is blocked by some firewalls and browser configurations.
You can limit the blocking to certain files or directories by putting a <files> or <directory> tag around the code. When using the <files> tag you can specify a file name or a file type. See the example below:
You can expand this to block multiple IPs or domain names and create a special error page. Create and upload a special page, in this example banned.htm, then use this in .htaccess:
You can also use this technique to make a private website (or directory) by restricting access by IP address.
Using the .htaccess lines below, only requests from the specified IP address will be allowed:
More information can be found on these techniques in the Apache documentation here, at the bottom of that page.
Code: Select all
order deny,allow
deny from 192.11.22.33
deny from badwebsite.com
You can also use a partial domain name.
Note that blocking by domain name depends on the browser sending the referrer code, which is blocked by some firewalls and browser configurations.
You can limit the blocking to certain files or directories by putting a <files> or <directory> tag around the code. When using the <files> tag you can specify a file name or a file type. See the example below:
Code: Select all
<files image.gif>
order deny,allow
deny from 192.11.22.33
</files>
Code: Select all
ErrorDocument 403 /banned.htm
order deny,allow
deny from 192.11.22.33
deny from 192.77.88
<files banned.htm>
allow from all
</files>
Using the .htaccess lines below, only requests from the specified IP address will be allowed:
Code: Select all
order allow,deny
allow from 192.11.22.33