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?

1 Answer 1


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
  • 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? Sep 30, 2011 at 20:36
  • 1
    Sure just use the code I have you, remove the .inc part and place it in your includes directory.
    – John Conde
    Sep 30, 2011 at 20:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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