You want hotlinking protection. In a .htaccess file in /files
- Code: Select all
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(https?://(www\.)?domain\.com(/.*)?)?$ [NC]
RewriteRule .* - [F,L]
The above will send a forbidden header, if you would like to send an image instead you'd replace the RewriteRule with
- Code: Select all
RewriteRule !^files/hotlinking\.gif$ /files/hotlinking.gif [R,L]
If you wanted to send an image when images are requested, a CSS file when CSS is requested, etc. you'd do something like this
- Code: Select all
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(https?://(www\.)?domain\.com(/.*)?)?$ [NC]
RewriteRule .* - [L]
# If it's an image, send the hotlinking image file
RewriteCond %{REQUEST_URI} !^/files/hotlinking\.gif$ [NC]
RewriteRule \.(gif|jpe?g|png)$ /files/hotlinking.gif[R,L]
# If it's .css, send the hotlinking css file
RewriteCond %{REQUEST_URI} !^/files/hotlinking\.css$ [NC]
RewriteRule \.css$ /files/hotlinking.css [R,L]