Prevent hotlinking using .htaccess

4 Responses

  1. Asho says:

    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

    • Anonymous says:

      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

  2. Asho says:

    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

    • itzurkarthi says:

      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

Leave a Reply

Your email address will not be published. Required fields are marked *