Comments on: Prevent hotlinking using .htaccess https://w3lessons.info/prevent-hotlinking-using-htaccess Tutorials on PHP, jQuery & Amazon Web Services Sat, 24 Dec 2011 13:24:00 +0000 hourly 1 https://wordpress.org/?v=6.6.2 By: Anonymous https://w3lessons.info/prevent-hotlinking-using-htaccess#comment-50 Sat, 24 Dec 2011 13:24:00 +0000 http://w3lessons.info/?p=234#comment-50 In reply to Asho.

Hi Asho..

below code is used to prevent hotlinking for all domain and subdomain too..

RewriteEngine On
#Replace ?mysite.com/ with your blog url
RewriteCond %{HTTP_REFERER} !^http://(.+.)?mysite.com/ [NC]
RewriteCond %{HTTP_REFERER} !^http://(.+.)?subdomain.mysite.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
#Replace /images/nohotlink.jpg with your “don’t hotlink” image url
RewriteRule .*.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpg [L]

The .htaccess file can be placed on any folder on your site. It has recursive effect. This means that if you place the .htaccess file in your web root (the main folder of your web site) the directives and commands you place in the .htaccess file will have effect on all sub-folders.
If you place a .htaccess file in a sub-folder, its directives will override the ones that you have in your site main folder.

Thanks

]]>
By: itzurkarthi https://w3lessons.info/prevent-hotlinking-using-htaccess#comment-52 Sat, 24 Dec 2011 13:24:00 +0000 http://w3lessons.info/?p=234#comment-52 In reply to Asho.

Hi Asho..

below code is used to prevent hotlinking for all domain and subdomain too..

RewriteEngine On
#Replace ?mysite.com/ with your blog url
RewriteCond %{HTTP_REFERER} !^http://(.+.)?mysite.com/ [NC]
RewriteCond %{HTTP_REFERER} !^http://(.+.)?subdomain.mysite.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
#Replace /images/nohotlink.jpg with your “don’t hotlink” image url
RewriteRule .*.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpg [L]

The .htaccess file can be placed on any folder on your site. It has recursive effect. This means that if you place the .htaccess file in your web root (the main folder of your web site) the directives and commands you place in the .htaccess file will have effect on all sub-folders.
If you place a .htaccess file in a sub-folder, its directives will override the ones that you have in your site main folder.

Thanks

]]>
By: Asho https://w3lessons.info/prevent-hotlinking-using-htaccess#comment-49 Sat, 24 Dec 2011 11:52:00 +0000 http://w3lessons.info/?p=234#comment-49 this code will work great, but i have a doubt,,, i have a subdomain,,, do this work for subdomain?? and also where i want to place this htaccess file for subdomain

]]>
By: Asho https://w3lessons.info/prevent-hotlinking-using-htaccess#comment-51 Sat, 24 Dec 2011 11:52:00 +0000 http://w3lessons.info/?p=234#comment-51 this code will work great, but i have a doubt,,, i have a subdomain,,, do this work for subdomain?? and also where i want to place this htaccess file for subdomain

]]>