The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Blocking Direct Image Loads in Browser with htaccess
Nick
post Feb 21 2007, 07:04 PM
Post #1


Member
***

Group: Members
Posts: 32
Joined: 29-September 06
Member No.: 268





Is there any way at all to stop images from being displayed when their URLs are typed directly into a browser? I don't really care if people can load them into web pages, I just want to stop people from typying http://www.blah.com/blah.jpg into a browser and seeing an image. Instead I want to redirect them to something else... a page of all images perhaps.

Any thoughts?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Effovex
post Feb 21 2007, 10:11 PM
Post #2


Serious Coder
*****

Group: Members
Posts: 251
Joined: 6-January 07
From: Sherbrooke, Qc, Canada
Member No.: 1,477



Not really possible. You could in theory check if the referer header is set, and if it's not redirect to the gallery, but that would prevent users who have disabled that (optional) part of HTTP from seeing your images. The best thing you can do is have http://www.blah.com/images/blah.jpg and have http://www.blah.com/images/ contain the gallery. This way people who want to access the gallery just have to remove blah.jpg to get there (or, in Opera, hold right-click, mouse up, mouse left, release right-click)
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Feb 22 2007, 03:42 AM
Post #3


Jocular coder
********

Group: Members
Posts: 2,460
Joined: 31-August 06
Member No.: 43



Can you explain why you want this? Is it so that essentially the images can only be viewed after the user has seen the gallery page? I can tell you how to do this...
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Peter1968
post Feb 22 2007, 05:23 AM
Post #4


Serious Coder
*****

Group: Members
Posts: 448
Joined: 23-September 06
Member No.: 213



I don't know if this is the way Brian has in mind, but you could limit the full picture to those who are logged in users.

Anyone can see the gallery/thumbnail page but it requires authorisation to view the actual pictures.

There are many sites out there now that do this.

Many gallery scripts out there also offer this type of functionality, including I believe, Gallery itself.

http://gallery.menalto.com
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Nick
post Feb 23 2007, 02:20 AM
Post #5


Member
***

Group: Members
Posts: 32
Joined: 29-September 06
Member No.: 268





Thanks guys... here's the reason: A lot of people come to my site from google image searches. They typically just click on the full sized view of the image and leave. I'd rather they stick around. So I don't want them to be able to click from google image search to see the full sized image. I'd rather they be redirected to a particular page....that invites them to do other things.


On a related note, I slapped the following into my htaccess:

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


This works great, except for one complication - my images are actually on another server, called images.mydomain.com - that's where the aforementioned htaccess file lives. No problem whatsoever, except for people who use Internet Explorer for PC. Those people get a page full of dead images when they look at mydomain.com ... why would ONLY IE get skunked? Firefox, Opera, Safari all work fine!




User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Feb 23 2007, 03:16 AM
Post #6


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
Joined: 9-August 06
Member No.: 6



I don't know, sounds odd. Sure the page isn't cached somehow? But dead images is what will show at Google Images too. And it's what users who's browser doesn't send referrer will see. I wonder if it isn't easier to just disallow Google Images.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Nick
post Feb 23 2007, 03:40 AM
Post #7


Member
***

Group: Members
Posts: 32
Joined: 29-September 06
Member No.: 268



yeah... good point. I'm going to let this one go! Thanks though.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Peter1968
post Feb 23 2007, 04:03 AM
Post #8


Serious Coder
*****

Group: Members
Posts: 448
Joined: 23-September 06
Member No.: 213



I personally use this setup:

CODE

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mysite\.com [NC]
RewriteCond %{HTTP_REFERER} !google\. [NC]
RewriteCond %(HTTP_REFERER) !yahoo\. [NC]
RewriteCond %(HTTP_REFERER) !altavista\. [NC]
RewriteCond %{HTTP_REFERER} !alltheweb\. [NC]
RewriteCond %{HTTP_REFERER} !wikipedia\. [NC]
RewriteCond %{HTTP_REFERER} !search\?q=cache [NC]
RewriteCond %{HTTP_REFERER} ^http:// [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule \.(jpe?g|gif|png)$ - [F]


It allows referrers from Google and others and effectively blocks others (as well as that method allows anyway)

And, I've no idea why IE would be thrown off by that as it's a server side thing and it's all done before IE even gets it.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Feb 24 2007, 12:08 AM
Post #9


Jocular coder
********

Group: Members
Posts: 2,460
Joined: 31-August 06
Member No.: 43



QUOTE
Thanks guys... here's the reason: A lot of people come to my site from google image searches. They typically just click on the full sized view of the image and leave. I'd rather they stick around. So I don't want them to be able to click from google image search to see the full sized image. I'd rather they be redirected to a particular page....that invites them to do other things.


Surely Google images shows the image, and also the page in which it appears. If people take one look at your image and leave, I suggest the most likely reason is that they aren't interested in the site. If you are searching for something, you typically find many sites which may be very worthy, but aren't what you are looking for - when I meet trickery intended to make sure I look at what the siteowner thinks I ought to want to look at, I generally get annoyed, and leave even faster.

Also, I imagine that if google says "Here is an image", but a person attempting to access the image actually gets something else, this would be instant reason for total deletion from Google images (rightly so).

I have a small problem with hot-linking, in that people are using pictures from puzzles to decorate their blogs and things, and the pictures aren't mine. So (when I get round to adding higher resolution images) I intend to use dynamically generated urls, which will only be valid for 24 hours or so.

(I'm not familiar with Apache rewrite rules, so I can't see quite what's going on in the various suggestions..., but it seems to me that anything based on refer*left-bracket-damnit*r*right-bracker-damnit*ers is not terribly reliable...)
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Peter1968
post Feb 24 2007, 12:35 AM
Post #10


Serious Coder
*****

Group: Members
Posts: 448
Joined: 23-September 06
Member No.: 213



It's more reliable than you think it is. No method is 100% effective, but the mod_rewrite method I've shown does work in nearly all cases.

Enough to where I save several GB a month, anyway.

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Feb 24 2007, 04:54 AM
Post #11


Jocular coder
********

Group: Members
Posts: 2,460
Joined: 31-August 06
Member No.: 43



QUOTE(Peter1968 @ Feb 24 2007, 02:35 PM) *

It's more reliable than you think it is. No method is 100% effective, but the mod_rewrite method I've shown does work in nearly all cases.

Enough to where I save several GB a month, anyway.


Can you just explain in English what your list of Apache rules does?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 28th March 2024 - 05:04 AM