Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.


share|improve this question
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

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

Your Answer


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.