Forum Moderators: phranque

Message Too Old, No Replies

Restrict Access to directory directly

I need some help.

         

doughboy 300

1:53 am on Oct 20, 2009 (gmt 0)

10+ Year Member



Okay this is my first post to a message board (not one like this, but in general). I have a folder within a site with photos in it. I want to make it so that people can't view the photos unless it is referenced from another page within my site.

I don't want them to be able to see the picture simply by entering the direct address:


www.example.com/photos/image.jpg

but I still want to be able to get to the picture from another page:

<img src="/photos/image.jpg" />

Do not show the picture: www.example.com/photos/image.jpg
Show the picture: www.example.com/index.html using <img src="/photos/image.jpg" />

I have tried the whole RewriteRule ^..... thing, but can't seem to get the hang of it, if this is how you would go about doing this at all? I do not have access to the conf file as I am using paid a web host.

I have searched and searched and search and can't figure it out. I hope this makes sence. Any help would be greatly appreached.

Many thanks!

jdMorgan

3:14 am on Oct 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need to do some scripting (write or buy a program). Here's an outline of one method that will work:
On the "authorized" page or pages of you site, set a client-side cookie.
In your .htaccess file, rewrite requests for all images in your 'protected' directories to a script.
In this script, validate the cookie.
If the cookie is present and valid, open the image filepath, and serve the content to the client.
If the cookie is not present or is not valid, serve an alternate image telling the visitor he needs to visit the page on your site, or she needs to log in, or whatever is appropriate.

That's a simple approach that can work.

Jim

doughboy 300

3:52 am on Oct 20, 2009 (gmt 0)

10+ Year Member



Wow... That was a really simple solution. I almost feel kind of foolish now for even asking...

You know when you have been working on something WAY too long when the answer is right in front of your face but you are to blind to see it!

Many thanks!

callivert

4:04 am on Oct 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If I want to block access to a folder, I create a small index.html file, less than 1k in size, that says somthing like "hi you can't view these files, sorry." I then dump the index.html in the folder I want to block. It seems to work.

g1smd

3:05 pm on Oct 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



An alternative to adding the index file is set
Options -Indexes