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

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
add comment

1 Answer

up vote 3 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
</Files>

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

# 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
1  
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
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.