Stop hotlinking And Serve alternate content
Using .htaccess, you can disallow hot linking on your server, so those attempting to link to an image, video, music, flash, zip/rar, CSS file on your site, for example, is either blocked (failed request, such as a broken image) or served a different content (ie: an image of an angry man) . Note that mod_rewrite needs to be enabled on your server in order for this aspect of .htaccess to work. Inquire your web host regarding this.
A. Stop hotlinking
To simply stop hotlinking you can add the following to your .htaccess file. Replace mysite.com on line 3 with your own domain name.
RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http://(www\.)?mysite.com/.*$ [NC] RewriteRule \.(gif|jpg|jpeg|bmp|zip|rar|mp3|flv|swf|xml|php|png|css|pdf)$ - [F]
B. Serve alternate content
To serve alternate content when hotlinking is detected. You can set up your .htaccess file to actually display different content when hotlinking is attempted. This is more commonly done with images suggesting your displeasure of this activity, such as serving up an “XYZ” image in place of the hotlinked one. Once again, replace mysite.com on lines 3 and 4 with your own domain name.
RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite.com/.*$ [NC] RewriteRule .*\.(gif|jpg|jpeg|bmp|png)$ http://mysite.com/XYZ.gif [L]
allow with your another sub domain, exp : the sub domain name is subdomain, sub2 and sub3
RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite.com/.*$ [NC, OR] RewriteCond %{HTTP_REFERER} !^http://(.+\.)?subdomain.mysite.com/.*$ [NC, OR] RewriteCond %{HTTP_REFERER} !^http://(.+\.)?sub2.mysite.com/.*$ [NC, OR] RewriteCond %{HTTP_REFERER} !^http://(.+\.)?sub3.mysite.com/.*$ [NC] RewriteRule .*\.(gif|jpg|jpeg|bmp|png)$ http://mysite.com/XYZ.gif [L]
Key : Stop hotlinking And Serve alternate content
Related Posts
PHP, Rounding and Formatting Numbers The PHP Date() Function