Htaccess Cheat Sheet PDF
Htaccess Cheat Sheet PDF
by Jean-Philippe Ct - www.cote.cc
Block hotlinking
Example :
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ - [F]
To serve alternate content to hotlinkers, substitute last line above with :
RewriteRule \.(gif|jpg|png)$ http://www.example.com/blocked.gif [R,L]
Block access from specic referers
Example :
RewriteEngine on
RewriteCond %{HTTP_REFERER} example\.com [NC]
RewriteRule .* - [F]
Redirect to domain name without www prex
Example :
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Redirect to domain name with www prex
Example :
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
Block access from specic IP blocks
Example :
order allow,deny
deny from 123.45.6.7
deny from 12.34.5.
allow from all