diff --git a/README.md b/README.md index 87585c9..cb986e0 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ What we are doing here is mostly collecting useful snippets from all over the in - [Deny Access to Backup and Source Files](#deny-access-to-backup-and-source-files) - [Disable Directory Browsing](#disable-directory-browsing) - [Disable Image Hotlinking](#disable-image-hotlinking) + - [Disable Image Hotlinking for Specific Domains](#disable-image-hotlinking-for-specific-domains) - [Password Protect a Directory](#password-protect-a-directory) - [Password Protect a File or Several Files](#password-protect-a-file-or-several-files) - [Performance](#performance) @@ -228,9 +229,28 @@ Options All -Indexes ### Disable Image Hotlinking ``` apacheconf RewriteEngine on +# Remove the following line if you want to block blank referrer too RewriteCond %{HTTP_REFERER} !^$ -RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain.com [NC] + +RewriteCond %{HTTP_REFERER} !^http(s)?://(.+\.)?yourdomain.com [NC] +RewriteRule \.(jpg|jpeg|png|gif|bmp)$ - [NC,F,L] + +# If you want to display a "blocked" banner in place of the hotlinked image, +# replace the above rule with: +# RewriteRule \.(jpg|jpeg|png|gif|bmp) http://yourdomain.com/blocked.png [R,L] +``` + +### Disable Image Hotlinking for Specific Domains +Sometimes you want to disable image hotlinking from some bad guys only. The following snippet should help you with that. +``` apacheconf +RewriteEngine on +RewriteCond %{HTTP_REFERER} ^http(s)?://(.+\.)?badsite\.com [NC,OR] +RewriteCond %{HTTP_REFERER} ^http(s)?://(.+\.)?badsite2\.com [NC,OR] RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L] + +# If you want to display a "blocked" banner in place of the hotlinked image, +# replace the above rule with: +# RewriteRule \.(jpg|jpeg|png|gif|bmp) http://yourdomain.com/blocked.png [R,L] ``` ### Password Protect a Directory