Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

at "webmasters.stackexchange.com" I already found a similar topic: Stop directory listing using .htaccess and redirect to good error page

Options -Indexes
ErrorDocument 403 /path/to/403.html

However, now I want to distinguish between whether there was actaully a directory listing request issued OR if the user tried to access a protected area (through htaccess) unsuccessfully.

Both fire a 403, now how do I know which was the reason (the directory listing or the htaccess AuthName... thing) ?

share|improve this question
    
I am not sure you can without mod_perl. I can't think of anything yet. –  closetnoc Apr 18 at 15:44
    
What do you want to do if it was a directory request OR protected area? Any reason why you can't check this in your 403 document itself? –  w3d Apr 18 at 17:00

2 Answers 2

A request for a directory listing will have a URL that ends in /.

So http://example.com/images/ will be a 403 because of the directory listing.

http://example.com/private/document.html will be a 403 because of your rule for the private directory.

share|improve this answer
    
Unfortunately, this won't work with my situation as I have a folder called like "private" that is protected but there is an index file in there, so requesting that file could be done via "example.com/private/"; which has a trailing slash NOT because of the directory listing but because of the .htaccess protection. –  Terminello Apr 20 at 14:32
up vote 1 down vote accepted

Finally it worked by putting an additional line in the .htacces of the protected folder (call it private)

ErrorDocument 403 /forbidden-because-of-protection

and in the root's .htaccess I put the line like

ErrorDocument 403 /forbidden-because-of-directory-listing

So now when there is some request issued like /private/some/thing/bla the first .htaccess rule will be called - thus redirecting to /forbidden-because-of-protection otherwise like requesting a directory listing (thus not in /private) apache goes for the second rule.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.