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

Preferably using .htaccess files, though .conf files are an option, is there any way to stop Apache serving certain filetypes?

For example, .db shouldn't be served for obvious reason (privacy and whatnot, etc.), so could I make them show as a 404 but still have them available for my CGI scripts?

Putting these sensitive files in a directory other than /public_HTML/ is also an option, though I like having them in the same directory as the scripts for ease of use.

Cheers

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

I would have said that placing these sensitive files above the document root would be preferable. And perhaps easier to manage if they are all contained in a particular directory, however...

Using .htaccess to prevent access to all .db and .exe files and return a 403 - Forbidden.

<Files ~ "\.(db|exe)$">
Deny from all
</Files>

Unless you have a specific requirement, I would have thought a 403 would be better than a 404 in this instance, and this would seem more natural for Apache. To return a 404 here would require additional code.

share|improve this answer
    
Perfect! Thanks heaps –  ProfSmiles Sep 30 '12 at 6:03
add comment

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.