# Apache2 configuration problem

## zeuz

If I don't have an index file in a directory it displays the files. Searched some and found out that you should remove the 'Indexes' part from

```
<Directory />

    Options Indexes FollowSymLinks

    AllowOverride None

</Directory>

```

But it was never there...   :Embarassed: 

I have a .htaccess file in a directory that doesn't work as it did before. Now it doesn't show folders first.

```
Options +indexes

IndexOptions FancyIndexing FoldersFirst
```

Since I havent changed anything with that file I guess it's something that overrides the .htaccess file in the config.

Thanks, Stefan.

----------

## jmbsvicetto

 *zeuz wrote:*   

> If I don't have an index file in a directory it displays the files. Searched some and found out that you should remove the 'Indexes' part from
> 
> ```
> <Directory />
> 
> ...

 

Hi.

This post should have been made in the Networking & Security forum.

The following directive in your directory, prevents the .htaccess files from overriding your options.

```
    AllowOverride None
```

----------

## Earthwings

Moved from Installing Gentoo to Networking & Security.

----------

## zeuz

Sorry for the misplacing. 

Changed AllowOverride None to AllowOverride All, didn't help.   :Sad: 

----------

## jmbsvicetto

 *zeuz wrote:*   

> Sorry for the misplacing. 
> 
> Changed AllowOverride None to AllowOverride All, didn't help.  

 

Don't go from one extreme to the other, you may latter be sorry for that.  :Wink:  I think you just need to use AllowOverride Indexes.

Did you check the .htaccess file permissions? I don't know if Apache will accept to read files with too permissive file modes.

----------

## zeuz

Ohh...   :Embarassed:  I've thought of file permissions, but since it displays the files it couldn't be that.

----------

## jmbsvicetto

Do you mean that Apache shows you the contents of the .htacess file? If so, it shouldn't.

You should have the following snipet in httpd.conf.

```
<Files ~ "^\.ht">

  Order allow,deny

  Deny from all

</Files>
```

----------

## zeuz

No, the .htacess is hidden, but it doesn't order folders first. And directorys without an index-file exposes it's contents. That's what i'm having problems with.

----------

## zeuz

Does anyone have an idea on what could be wrong?

----------

## jmbsvicetto

 *zeuz wrote:*   

> No, the .htacess is hidden, but it doesn't order folders first. And directorys without an index-file exposes it's contents. That's what i'm having problems with.

 

zeuz,

I'm sorry, but I can't understand what you are trying to do!

Do you want apache to list the files if you don't have an index file? If so, are you complaining about the order apache displays the files and folders? What were you expecting?

----------

## zeuz

If the directory don't have an index file I want apache to display the error message for that. And my files/ dir with the htaccess file should order folders first, but it doesn't. (it did before reinstalling the server)

----------

## jmbsvicetto

OK! Now I understand what you want to do.

Please post the config of your directory entries in apache and the contents of your .htaccess files.

----------

## jmbsvicetto

After looking at the apache documentation, are you using the following in your .htaccess files?

```
<Directory ...>

   IndexOptions FoldersFirst

</Directory>
```

----------

## zeuz

```
Options +indexes

IndexOptions FancyIndexing FoldersFirst
```

That's how the .htaccess looks like. I haven't changed anything in it since i reinstalled the server.

I managed to get folders first by adding "IndexOptions FancyIndexing FoldersFirst" at the <Directory /> part in the config but the problem is that when there isn't a index file in a dir, it displays the files. I want it to display an error message.

----------

## jmbsvicetto

I've understood what you want, but you didn't include the directory entries configuration.

If you look at your http.conf file, you should find that the autoindex_module is being loaded. If you comment it out and restart apache, it should stop creating an automatic index for directories without index.* files. You should then create a redirect page for the 404 error.

----------

## zeuz

I'm not sure if this is what you want to see..

```
<Directory />

    Options FollowSymLinks -Indexes

    AllowOverride Indexes

</Directory>

```

I added the -Indexes and it works, except that it says "not found" instead of forbidden. If i remove the autoindex_module I wont be able to have my files/ directory?

----------

## jmbsvicetto

I thought that the problem might lay in the directory entries. Afterwards, I found out that it seems to be related to module_autoindex.

I've tried to solve your issue on my apache server and found out that after preventing apache from loading the module, I was still able to access the files inside the dirs, but that I would get a 404 error if I didn't had an index.* file and tried to open the dir. Isn't this what you want? You would just have to include a redir page for the 404 error.

----------

## zeuz

The 404 error is ok, it does what i want - hide directories that doesn't have index files. The only problem now is that i can't get the .htaccess to work with my files/ dir.

----------

## jmbsvicetto

Have you changed the root entry in /etc/apache2/httpd.conf to allow the override?

After looking at your previous posting, I would try to use the following:

```
<Directory />

    Options FollowSymLinks

    AllowOverride Indexes

</Directory> 
```

----------

## zeuz

Nothing changed, i'm still getting the 404 message when trying to access files/...   :Embarassed: 

----------

## jmbsvicetto

Well, I'm able to access files on my server, to open a dir with an index file (index.php) and get a 404 error if trying to open a dir without an index file.

My /etc/apache2/httpd.conf is as follows:

```
...

<IfDefine INFO>

    LoadModule info_module               modules/mod_info.so

    LoadModule status_module             modules/mod_status.so

</IfDefine>

LoadModule actions_module                modules/mod_actions.so

#LoadModule autoindex_module              modules/mod_autoindex.so

LoadModule dir_module                    modules/mod_dir.so

...

<Directory />

    Options FollowSymLinks

    AllowOverride None

</Directory>

...

DirectoryIndex index.html index.html.var

...

AccessFileName .htaccess

...

<Files ~ "^\.ht">

    Order allow,deny

    Deny from all

</Files>

```

If you try to open http://jmbsvicetto.homelinux.org/gentoo/ you'll get a 404 error, because I don't have an index file. Howerver, you can open http://jmbsvicetto.homelinux.org/gentoo/kernel-config-amd64 and https://jmbsvicetto.homelinux.org/horde/ - although I'm having a problem with SSL connections from the exterior.

----------

## zeuz

I've checked the config and it matches what you wrote above. The .htaccess file still won't work.  :Sad: 

----------

## jmbsvicetto

In that case I'm getting out of ideas. As a final test, what version of apache do you have? I have 2.0.54-r31.

----------

## zeuz

Server version: Apache/2.0.54

----------

