Welcome to WebmasterWorld Guest from 54.198.87.238

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

htaccess instead of listing files - show 404 page?

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

5+ Year Member



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)

WebmasterWorld Administrator incredibill is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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)

WebmasterWorld Senior Member wilderness is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



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:

Warning
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)

5+ Year Member



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

Options -Indexes

or

Options All -Indexes

In my htaccess file?
10:01 pm on Feb 24, 2012 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



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.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month