Skip to content

Instantly share code, notes, and snippets.

@janus57
Last active August 29, 2015 14:24
Show Gist options
  • Save janus57/22986007daaff6ed8867 to your computer and use it in GitHub Desktop.
Save janus57/22986007daaff6ed8867 to your computer and use it in GitHub Desktop.
block specific domain against hotlinking
# Methode 1
# block specific domains
<IfModule mod_rewrite.c>
RewriteEngine On
# match example.org/com etc...
RewriteCond %{HTTP_REFERER} ^http://([^.]+\.)?example\. [NC]
# rewrite to specific file
RewriteRule \.(gif|jpg|bmp|jpeg|png)$ http://example.org/bad.jpg [R,NC,L]
</IfModule>
# Methode 2
# block specific domains
<IfModule mod_rewrite.c>
RewriteEngine On
# match example.org/com etc...
RewriteCond %{HTTP_REFERER} ^http://([^.]+\.)?example\. [NC]
# rewrite send HTTP 403
RewriteRule \.(gif|jpg|bmp|jpeg|png)$ - [R,NC,F,L]
</IfModule>
# Methode 3
# block specific domains
<IfModule mod_rewrite.c>
RewriteEngine On
# match example.org/com etc...
RewriteCond %{HTTP_REFERER} ^http://([^.]+\.)?example\. [NC]
# rewrite to specific file
RewriteRule \.(gif|jpg|bmp|jpeg|png)$ http://example.org/bann.php [R,NC,L]
</IfModule>
<?php
header('WWW-Authenticate: Basic realm="Le hotlinking c\'est mal !"');
header('HTTP/1.0 401 Unauthorized');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment