tags:

views:

21

answers:

1

What I have in each directory.

<Files *>
    Deny From All
</Files>

I would like to put an htaccess file in my root main directory that does this:

1- prevents root access to any folder.

2- Redirects the user to one url should he try to access any root.

3- Still allow scripts to run and write in those directories publicly.

I also want to make sure that if an index,htm(l)/ or ,php file exists, that is loaded normally.

I seem to be struggling in figuring this out.

Thanks in advance for rewriting this beginner in the right direction.

+1  A: 
# No root access without index.*
Options -Indexes
DirectoryIndex index.php index.html index.htm

# Rewrite
RewriteEngine On
RewriteBase /

# Existing file
RewriteCond %{REQUEST_FILENAME} !-f
# Existing directory
RewriteCond %{REQUEST_FILENAME} !-d
# Symbolic link
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^ your-default-file.html [L]    

I’m not sure about your point 3. The webserver doesn’t know if an user agent is a script or a browser.

toscho
I think this'll work perfectly.
Litso
I still want the scripts to run and "pages" to load normally for users coming in from where ever. Sorry I was not clear on that.
Jim_Bo
What if I want to redirect them to a url? Will that still work on the last rewrite rule there?
Jim_Bo
Not working. Directories with index.html are still being redirected to the file or url in the last rule. I only want directories without an index.html or index.php to be redirected.
Jim_Bo
The code above works for its' purpose but, i would have to put it in each directory and point it to that directories index.htm / index.php file (or whatever file).
Jim_Bo
The code works from the root directory; you don’t have to create duplicates. If it doesn’t take a look into the rewrite log. Make sure no other rewrite rules interfere with these rules.
toscho
No other rewrite rules exist. If I try to access a directory that contains an index file, I am still redirected to your-default-file.html.
Jim_Bo
Is your index.html really registered? I added a DirectoryIndex rule for a demonstration how to do that.
toscho