Forum Moderators: phranque

Message Too Old, No Replies

No way to redirect direct linking to images?

         

maccas

2:57 pm on Feb 8, 2007 (gmt 0)

10+ Year Member



I am not talking about hotlinking but rather someone linking directly to image.gif. Is there nothing that can be done apart from just renaming the image?

maccas

3:05 pm on Feb 8, 2007 (gmt 0)

10+ Year Member



Never mind, just had my .htaccess in the wrong folder *idiot*, I just presumed you couldn't redirect a image request to a html page.

jdMorgan

3:26 pm on Feb 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, you can't reliably redirect an image request to an html page, because the browser loads pages and images in different ways. If an image URL is typed-in, then you can redirect it to an HTML page, but if the image URL is requested based on an <img> tag on an HTML page, then you can't -- the browser won't handle it properly because the <img> tag processing does not support/expect a MIME-type of text/html for an image request response.

You might also want to check out this current thread [webmasterworld.com] for a cautionary tale about blocking blank referrers.

Jim

maccas

3:41 pm on Feb 8, 2007 (gmt 0)

10+ Year Member



Thanks jdMorgan, it's just a simple <a href="http:// mysite/images/mypic.gif">my pic</a> link, I know it isn't going to be 100% but this seems to work fine.

RewriteEngine on
RewriteCond %{HTTP_referer} ^http://(www\.)?theirsite\.com [NC]
RewriteRule (.*) http:// mysite/folder/file.html [R=301,L]

I know hotlinking to a image can't be redirected to a html page, darn it.

jdMorgan

11:06 pm on Feb 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes that should work as long as the client provides a referrer header. If not, there's not much that can be done... :(

Jim

maccas

11:38 am on Feb 28, 2007 (gmt 0)

10+ Year Member



Thanks, how could I get it to redirect based on request_uri? I tried the following

Rewritecond %{REQUEST_URI}!^/image1\.gif [NC]
RewriteCond %{HTTP_referer} ^http://(www\.)?website1\.com [NC,OR]
RewriteCond %{HTTP_referer} ^http://(www\.)?website2\.co.uk [NC,OR]
RewriteCond %{HTTP_referer} ^http://(www\.)?website3\.com [NC]
RewriteRule (.*) http:// mysite/file.html [R=301,L]

But it doesn't work, if someone requests image2 it also gets redirected to mysite/file.html

jdMorgan

2:04 pm on Feb 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The "!" in the first RewriteCond means "NOT". So this code redirects every URL except image1 to your HTML file. It sounds like that is not what you want.

Jim

maccas

2:20 pm on Feb 28, 2007 (gmt 0)

10+ Year Member



Thanks again, I thought I already tried without it. Works a treat.