Search code examples
.htaccessurl-rewritingreferrerhotlinking

.htaccess allow hotlinking for one specific folder


I'll get straight to it. I have this code in my .htaccess file to prevent hotlinking, see below:

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://mywebsite.ca/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://mywebsite.ca$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mywebsite.ca/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mywebsite.ca$      [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC]

but I will have a few .jpg images up for banner exchange between sites and I don't know how to write the rule to allow hotlinking for just one folder. In this case the one folder will be root/image/links/

What changes in the rewrite conditions do I need to make to allow hotlinking for this one folder?

Thanks for your anticipated help everyone.


Solution

  • You can use

    RewriteCond %{REQUEST_URI} !^/image/links/
    

    as an additional condition.