Using an apache webserver, im currently redirecting hotlinks to a certain image.

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?camosreptiles.com.au/ [NC]
RewriteCond %{HTTP_REFERER} !google\. [NC] 
RewriteCond %{HTTP_REFERER} !search\?q=cache [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ http://i14.photobucket.com/albums/a345/Instar/nedry2.gif [NC,R,L]
</ifModule>

What id like to do, is redirect to a certain page (my own domain) if somebody pastes my image url into a browser, or uses an image url from my site in href. If they use image tags, i want to replace the image.
Not sure if this can be done anymore, I used to do this...

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(www\.)?camosreptiles.com.au(/)?.*$     [NC]
RewriteRule .*\.(gif|jpg|png|jpeg|bmp)$ http://www.camosreptiles.com.au/hotlink.shtml [R,NC]

and it used to work, but not anymore. If someone used image tags, it just showed a broken image.

Ive ream books worth of .htaccess stuff, but it all seems to be out of date and not work.

Is the above possible and can you show me how please? P.s. not sure if the coding is right for my .com.au domain?

Recommended Answers

All 6 Replies

Actually I just realised if I block empty referrers, then anyone using a proxy or behind a firewall etc may not be able to see pics on my site.

Is a conditional rewrite rule possible? for example:

If they do this..(anywhere but my domain)

<img src="http://www.mysite.com.au/mypic.gif"/>

They get a specific image instead, BUT..

If they do this....

<a href="http://www.mysite.com.au/mypic.gif"/><a great pic</a>

then when the link is clicked, it redirects to a specific page.

Thats what Id like to do, possible?

No, that does not seem possible. But I might not be understanding your question well enough.

To handle hotlinking:

The way I have seen this done and actually done myself a few times is to have a php script handle all image requests. You have php check for the referrer and output a different image if they do not meet your criteria.

To my knowledge another problem with that code is that the HTTP_REFERER does not always populate with a value. Sometimes it equals a blank value if the user has disabled sending that information in their browser. So it is best not to use HTTP_REFERER as some users will experience difficulties in your website due to having HTTP_REFERER disabled in their browser.

cheers cwarn23, whats an alternate format to HTTP_REFERER ?

There is a simple tutorial at the below link which will explain.
http://corz.org/serv/tricks/htaccess2.php
It is along the lines of the following but you will need to modify the code to suite your needs:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)\.htm$ $1.php [NC]

Basically what it does is create a symbolic link for the matching path where the path matches the regex and if it matches the regex then it will load the file in the second parameter.

Thanks again. This still doesnt quite allow for 2 options though, two rules depending on how an image is hotlinked, e.g image tag or hef
but ill have a play with it, cheers

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.