IP Blacklisting and IP Whitelisting with .htaccess

if you want to allow some user with specific IP addresses or you want to ban user some IP address. you can do it by IP address

Blacklisting by IP

To block specific addresses, as per following example first line makes allow from all the default state.only those are match with denied directives will be denied.

order allow,deny
deny from 111.33.55.66
deny from 35.34.6.6
allow from all

Whitelisting by IP

It is opposite of IP Blacklisting, as per below example everybody is restricted except "111.33.55.66" and "35.34.6.6"

order deny,allow
deny from all
allow from 111.33.55.66
allow from 35.34.6.*  #IP address wildcard

Block users by Domain name instead of IP address

As per example , You can also allow or bloack users depend on domain name. this will not work reverse-DNS IP mapping

order allow,deny
deny from example.com
allow from all

This works for subdomains, abc.example.com will also blocked

How to Block users by Referrer in .htaccess?

Referer request header contains a link of the previous website page that called referrer, it is not work on clickable hyper links og web page. If any website use the images of your website directly. This is called hotlinking. if you need to do, you have to activate "mod_rewrite" module.

RewriteEngine on
RewriteCond % ^http://.*example.com [NC,OR]
RewriteCond % ^http://.*htaccessexample.com [NC,OR]
RewriteCond % ^http://.*functionsexample.com [NC]
RewriteRule .* - [F]