Question

How can I prevent users from accessing a directory directly without preventing the files and sub directories being accessed? Please note that all my pages are written in php and the file type .php is omitted using htaccess url rewrites.

When I tried to attain waht I need using the following htaccess lines, I get 403 errors for all my url's, as they do not have a file type in them.

# Deny access to everything by default
Order Deny,Allow
deny from all

# Allow access to html files
<Files *.*>
    allow from all
</Files>

The .htaccess file is in the dir folder

When try to access http://www.domain.com/dir/sub/page I get a 403 error. But when I try to access http://www.domain.com/dir/sub/page.php (note the .php file type) everything works fine. How can I restrict the prohibition ONLY to DIRECTORIES, with respect to my rewrite rules?

I need to restrict direct access only to directories and sub directories. I need to access whatever the flies inside the directories and sub directories.

Related questions like this and this did not help me since the omission of file type was not applicable to those.

Was it helpful?

Solution

I need to restrict direct access only to directories and sub directories. I need to access whatever the flies inside the directories and sub directories.

What I meant was to prohibit directory listing. And show to 403 instead

You can try following rule:

# disable directory listing
Options -Indexes
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top