简体   繁体   中英

.htaccess Options -Indexes

I'm using a simple .htaccess file with the contents

Options -Indexes

to try and hide directory listings. However, when I try to load any page from the browser it gives me a 403 error for any page. Any ideas what the problem is?

For context, .htaccess is in the root folder that contains php files and folders of other php files included/required etc. by those in root.

Thanks in advance

Ben

Make sure that you have a proper directory index setting. The Indexes option simply tells apache to display the contents of the directory as the index if there isn't a default index in that directory.

So if you have the file:

/index.php

Make sure you have:

  1. A valid index file
  2. it is part of the list defined by DirectoryIndex
  3. It is readable by apache.

If your index.php is the file you want serves when the request is for the directory, then make sure it is readable by apache (644 is good enough ), then make sure it's in the list defined by the directory index:

DirectoryIndex index.php

One other thing that may be happening, and it's very specific to someone's website setup. If you have DirectorySlash Off somewhere, meaning apache won't automatically redirect the browser when a trailing slash is missing when a reqeust is for a directory, and you have Indexes turned off, then your index file will get ignored .

Example, if I have directory slash off, and a request for the directory is made:

/folder

without the trailing slash, it doesn't matter if you have a valid index file, it will get ignored without a trailing slash . If this is the case, make sure you really want to have trailing slashes removed for accesses to directories and this is a limitation of apache.

I had this problem and it was due to permissions. CHMOD it to 777 or whatever.

Also, consider this rule is run for each page load. For speed purposes you can create .htaccess for each folder.

也许您的文件夹权限,应该检查一下

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM