Secure Directories by IP Address and/or Domain

In the following example, all IP addresses are allowed access except for 12.345.67.890 and domain.com:

# allow all except those indicated here
<Limit GET POST PUT>
order allow,deny
allow from all
deny from 12.345.67.890
deny from .*domain\.com.*
</Limit>

 

In the following example, all IP addresses are denied access except for 12.345.67.890 and domain.com:

# deny all except those indicated here
<Limit GET POST PUT>
order deny,allow
deny from all
allow from 12.345.67.890
allow from .*domain\.com.*
</Limit>

This is how to block unwanted visitors based on the referring domain. You can also save bandwidth by blocking specific file types — such as .jpg, .zip, .mp3, .mpg — from specific referring domains. Simply replace “scumbag” and “wormhole” with the offending domains of your choice:

# block visitors referred from indicated domains
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_REFERER} scumbag\.com [NC,OR]
RewriteCond %{HTTP_REFERER} wormhole\.com [NC,OR]
RewriteRule .* – [F]
</ifModule>

Facebook
WhatsApp
Twitter
LinkedIn
Pinterest

Leave a Comment

Your email address will not be published. Required fields are marked *

Related Articles from the Series

Common Image WpDeveloperTips
Important Notes for .htaccess
As a configuration file, .htaccess is very powerful. Even the slightest syntax error (like a missing...
Common Image WpDeveloperTips
Change Default Index Page
This rule tells the server to search for and serve “business.html” as the default directory index. This...
Common Image WpDeveloperTips
Commenting .htaccess Code
Comments are essential to maintaining control over any involved portion of code. Comments in .htaccess...
Common Image WpDeveloperTips
Htaccess Definition
Apache server software provides distributed (i.e., directory-level) configuration via Hypertext Access files....
Common Image WpDeveloperTips
Redirect Old Domain to New Domain via .htaccess
When you migrate a site from one domain to another, it is very important that you don’t break all the...
Scroll to Top