Search code examples
apache.htaccesssearch-enginehttp-referer

Block hotlinking but whitelist certain pages / search engines


What I'm doing right now is to block hotlinking of any images in a certain folder and redirecting to the website containing that image:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com/.*$ [NC]
RewriteRule (.*)\.(gif|jpg|png)$ /$1.html [R,L]

What I want to do now is to whitelist certain pages

e.g. bing.com | google.com | google.fr | google.de | etc.

I guess that's quite an easy task but I'm terrible with .htaccess :/

Thanks for the help


Solution

  • You can try:

    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com/.*$ [NC]
    # add whatever other search engines you want to whitelist
    RewriteCond %{HTTP_REFERER} !(bing.com|google|yahoo) [NC]
    RewriteRule (.*)\.(gif|jpg|png)$ /$1.html [R,L]