2
0
Fork 0
mirror of https://github.com/phanan/htaccess.git synced 2018-11-08 13:39:40 +01:00

Merge branch 'master' of https://github.com/rez0n/htaccess into rez0n-master

This commit is contained in:
An Phan 2015-02-23 06:13:20 +08:00
commit 62e6063ec0

View file

@ -31,6 +31,8 @@ What I'm doing here is mostly collecting useful snippets from all over the inter
- [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 Fixed Domains with Block Banner](#disable-image-hotlinking-for-fixed-domains-with-block-banner)
- [Disable Image Hotlinking for Fixed Domains](#disable-image-hotlinking-for-fixed-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)
@ -226,6 +228,23 @@ RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]
```
If you want block 'blank' referers too - delete `RewriteCond %{HTTP_REFERER} !^$` line (not recommended).
### Disable Image Hotlinking for fixed domains
This settings disabling image hotlinking for fixed sites only.
``` apacheconf
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?badsite.com.*$
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]
```
### Disable Image Hotlinking for Fixed Domains with Block Banner
This settings - rewrite all hotlinked images for fixed domains to your 'blocking banner' (ex. Image with you site url or message about hotlinking image)
``` apacheconf
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?badsite.com.*$
RewriteRule \.(jpg|jpeg|png|gif) http://mysite.com/block_img.png [R,L]
```
### Password Protect a Directory
First you need to create a `.htpasswd` file somewhere in the system: