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 us
You do not need to create an index file like this-
<html>
<title>Forbidden!</title>
<body>
<h1>Access Denied !!</h1>
</body>
</html>
And place it in each resource directories and directories you don't want to show users.
You can just add this at the end of your .htaccess file-
Options -Indexes
So, your .htaccess
file may be like this-
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
Options -Indexes
</IfModule>
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.
in that folder which you want to show access forbidden create a file with name index.php and paste this code
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access This Folder
on this server.</p>
</body></html>
All you need to keep people from seeing the directory contents is an index.php or .html file in that folder. Any requests for yoursite.com/images will load index.php, which you'll set to a dummy page.
index.html could be something like:
<html><title>Forbidden!</title><body>Nothing to see here...</body></html>
or a redirect script index.php:
<?php header('Location: /index.php'); exit(); ?>
Don't use .htaccess for blocking directory listings, it blocks access to everything.
Simplest solution : create a blank page name index.html
in your image folder :)
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.
in .htaccess
Options -Indexes
http://httpd.apache.org/docs/current/mod/core.html#options