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

I've recently set up my first commercial website for someone, with godaddy hosting.

I want to set up a 403 forbidden on several directories (and their contents) that are referenced to through php only (e.g. /includes, /txt).

How can I set this up firstly so it's forbidden, and secondly, so it redirects to a custom page?

Also on godaddy I can't seem to get to the root of my server, it simply takes me to the 'html' folder, but I believe the .htaccess file is located at a higher-level directory. How can I access this?

share|improve this question
up vote 6 down vote accepted

Create an .htaccess file in the directory you wish to block, or your root HTML directory if you want this to affect your entire website. Place this code inside:

# Block includes if they have a .inc.php extension. Change
# that to match whatever extension you use for your includes.
<Files *.inc.php>
Order Deny,Allow
Deny from All

# Block access to .txt files
<Files *.txt>
Order Deny,Allow
Deny from All

# Create a custom page for all 403 errors
ErrorDocument 403 /misc/403.php
share|improve this answer
hi - I don't use .inc.php for includes, I just use .php. - is it not possible just to deny all files/folders in x directory? – Alex Coplan Sep 30 '11 at 20:36
Sure just use the code I have you, remove the .inc part and place it in your includes directory. – John Conde Sep 30 '11 at 20:37
thank you - very helpful – Alex Coplan Sep 30 '11 at 20:52

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.