homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

htaccess instead of listing files - show 404 page?

 2:51 pm on Feb 22, 2012 (gmt 0)

Hi all,

Is it possible - that if someone visits a "hidden" folder on my site - a htaccess file makes it look like the folder dosnt exist - with a 404 error page?

I have a folder full of swf games - and i would like the folder to not be accessed. I would love it if anyone trys to access /swf/ they get a 404 -- like the folder is not there.

But my site would still need access to the folder -- i just don't want the contents to be listed when someone visits the link. But the files in the folder would still need to be use?

Thanks so much for anyone who can help :)

(I did this: Options All -Indexes - but it shows the folder is not accessible - where i really don't want people to know its there at all)



 4:40 pm on Feb 22, 2012 (gmt 0)

How will people know the folder is there unless you publish links using the folder name?

Putting an index file in your folder blocks a directory listing.

Just make your index file say "Page not found" - much simpler than mucking around in .htaccess


 5:01 pm on Feb 22, 2012 (gmt 0)

UNTESTED, worth a try:

RewriteCond %{REQUEST_URI} /path-to-directory/\.swf
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example\.com [NC]
RewriteRule .* - [F]


 9:47 pm on Feb 22, 2012 (gmt 0)

Putting an index file in your folder blocks a directory listing.

So does a single-line htaccess file:

Options -Indexes

... except that you don't need to, because that's already your default isn't it?

The form
Options All -Indexes
is likely to be a big, big mistake:

Mixing Options with a + or - with those without is not valid syntax, and is likely to cause unexpected results.

When Apache docs put up a warning, pay attention. The "unexpected results" is a euphemism for "disastrously unwanted results" ;)


 11:42 am on Feb 24, 2012 (gmt 0)

Sorry i'm confused - would i be better to have:

Options -Indexes


Options All -Indexes

In my htaccess file?


 10:01 pm on Feb 24, 2012 (gmt 0)

The first. The second is the "unexpected results" version. And the line should go in your top-level htaccess, because auto-indexing would normally be off by default. (You can turn it on in individual directories.)

Turning specific options off or on has no effect on other options. The default is "All", which means ... "All except MultiViews". (At least it does in Apache 2.2. It may be necessary to add this disclaimer to all statements about Apache everywhere ;))

Any options preceded by a + are added to the options currently in force, and any options preceded by a - are removed from the options currently in force.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved