More specifically, I have an htaccess file that restricts anyone from seeing the directory contents. Such that, nobody can see my 1000s of images in www.example.com/images by using:
deny from all
allow from 127.0.0.1
However, I want to use these images on www.example.com such that,
<img src="images/thisimg.jpg" />
works.
I hope I'm in the right direction, but I appreciate any insight/re-direct. This is similar to: How to protect all directory contents, but gain access to php script but I want to link to these images in that directory, and using deny from all
does not allow me to do that.
Thanks in advance for your help.
Option 1 (Easy but not Preferable)-
You do not need to create an index file like this-
And place it in each resource directories and directories you don't want to show users.
Option 2 (More Preferable)-
You can just add this at the end of your .htaccess file-
So, your
.htaccess
file may be like this-If you do that and try to go to a directory, you would get something like this-
So, no one will be able to discover any directory in server.
More can be found here.
To me I feel the easiest way of getting it done is with a redirect. On the images directory, just create an index page and in the index page you have a redirect to your site index page i.e
So that whenever anyone tries to access the image page directly they end up going to your site's root.
deny from all
allows files to be used by server side scripts but restricts complete web access.I use a trick which makes people think they've accessed a folder which doesn't exist.
Create a HTML file and add this:
Magicianeer's suggestion is the best for this problem. If your images are broken into subfolders you'd have to put an index file in each one. 'Options -Indexes' only needs to be done once at the root.
Simplest solution : create a blank page name
index.html
in your image folder :)