htaccess hotlinking replace image

Status
Not open for further replies.

randomlande

i like tits
Jun 26, 2006
655
3
0
I know how to replace hotlinked images from my site with a single default image using the following code in my htaccess file

Code:
                  RewriteEngine On
                    RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
                    RewriteCond %{HTTP_REFERER} !^$
                    RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpe [L]

but what I want to do is display a different image for the hotlinked image. for example if image 123.jpg from the folder 'images' is hotlinked, i want the file 123.jpg from the folder 'watermarkedimages' to be displayed. How would I edit the htaccess code to do this?
 


There are different ones, but I want htaccess to show the corresponding image from 'watermarkedimages' when a user accesses an image from the folder 'images'
 
If I understand correctly what you're trying to do, the easiest method will simply be to create a script to save the filename of every image you want to do this with.

/images/imagename.jpg

then make another document/paste that data, and rename them all to /watermark/imagename.jpg

then do a simple redirect for hotlinking.

I know this is quite a job if you have a lot of images, but its a easy quick fix until someone can figure out the htaccess code that will work on your server.
 
I know how to replace hotlinked images from my site with a single default image using the following code in my htaccess file

Code:
                  RewriteEngine On
                    RewriteCond %{HTTP_REFERER} !^[URL="http://%28.+"]http://(.+[/URL]\.)?mysite\.com/ [NC]
                    RewriteCond %{HTTP_REFERER} !^$
                    RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpe [L]
but what I want to do is display a different image for the hotlinked image. for example if image 123.jpg from the folder 'images' is hotlinked, i want the file 123.jpg from the folder 'watermarkedimages' to be displayed. How would I edit the htaccess code to do this?

Replace the last line with something like:

Code:
RewriteRule images/^(.*)\.(jpe?g|gif|bmp|png)$ watermarked/$1 [L]

Prob not quite right, but something along those lines I think.
 
thanks lazzyhippy, you got me on the right track.
After about an hour of consulting documentation, I finally got it to work with the last line

Code:
RewriteRule ^images/(.*)\.jpg$ /watermarkedimages/$1\.jpg [L]
it was mostly a matter of figuring out where to put the start and end string characters and the correct format.
 
Status
Not open for further replies.