# Apache2 DirectoryIndex Override?

**URL:** <https://forums.suse.com/t/apache2-directoryindex-override/22305>\
**Category:** SLES Configure-Administer\
**Created:** [March 6, 2012, 4:54pm UTC](https://forums.suse.com/t/apache2-directoryindex-override/22305 "2012-03-06T16:54:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dalrain](https://avatars.discourse-cdn.com/v4/letter/d/8dc957/32.png) [@Dalrain](https://forums.suse.com/u/Dalrain)\
**Post date:** [March 6, 2012, 4:54pm UTC](https://forums.suse.com/t/apache2-directoryindex-override/22305/1 "2012-03-06T16:54:42Z")

</div>

Hello,  
We use SLES 10 and 11 at my workplace to provide web services using PHP apps. Unfortunately, I noticed that every time apache gets patched, it insists on replacing /srv/www/htdocs/index.html, which breaks the server by throwing “It Works!” at clients. I created a /etc/apache2/httpd.conf.local file and added it to /etc/sysconfig/apache2 as an INCLUDE, which has “DirectoryIndex index.php index.html index.htm” That directive is listed in order of preference, but the apache httpd still prefers the stupid index.htm. I know there’s a DirectoryIndex declaration in /etc/apache2/httpd.conf, but the instructions in that file say not to modify the file directly!

In addition, I see that the PHP file contains multiple DirectoryIndex declarations, each on their own line, which suggests the directive is additive. Help! How can I avoid the blasted “It Works!” index.html taking over every patch release?

Edit: Grammar

---

<div class="post-metadata">

**Author:** ![Dalrain](https://avatars.discourse-cdn.com/v4/letter/d/8dc957/32.png) [@Dalrain](https://forums.suse.com/u/Dalrain)\
**Post date:** [March 6, 2012, 5:26pm UTC](https://forums.suse.com/t/apache2-directoryindex-override/22305/2 "2012-03-06T17:26:33Z")

</div>

For the tl;dr crowd: How can I make Apache HTTPd prefer index.php over index.html, while respecting the advice in /etc/apache2/httpd.conf to not edit it directly?

---

<div class="post-metadata">

**Author:** ![smflood](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/smflood/32/10576_2.png) [@smflood](https://forums.suse.com/u/smflood)\
**Post date:** [March 9, 2012, 5:50pm UTC](https://forums.suse.com/t/apache2-directoryindex-override/22305/3 "2012-03-09T17:50:53Z")

</div>

On 06/03/2012 15:04, Dalrain wrote:  
[color=blue]

> We use SLES 10 and 11 at my workplace to provide web services using PHP  
> apps. Unfortunately, I noticed that every time apache gets patched, it  
> insists on replacing /srv/www/htdocs/index.html, which breaks the server  
> by throwing “It Works!” at clients. I created a  
> /etc/apache2/httpd.conf.local file and added it to  
> /etc/sysconfig/apache2 as an INCLUDE, which has “DirectoryIndex  
> index.php index.html index.htm” That directive is listed in order of  
> preference, but the apache httpd still prefers the stupid index.htm. I  
> know there’s a DirectoryIndex declaration in /etc/apache2/httpd.conf,  
> but the instructions in that file say not to modify the file directly!
> 
> In addition, I see that the PHP file contains multiple DirectoryIndex  
> declarations, each on their own line, which suggests the directive is  
> additive. Help! How can I avoid the blasted “It Works!” index.html  
> taking over every patch release?[/color]

In your /etc/apache2/httpd.conf.local try adding the following lines

\<Directory /srv/www/htdocs\>  
AllowOverride Indexes  
  
DirectoryIndex index.php index.html index.htm

## HTH.

Simon  
Novell/SUSE/NetIQ Knowledge Partner

* * *

## Do you work with Novell technologies at a university, college or school? If so, your campus could benefit from joining the Novell Technology Transfer Partner (TTP) program. See [novell.com/ttp](http://novell.com/ttp) for more details.

---

<div class="post-metadata">

**Author:** ![Dalrain](https://avatars.discourse-cdn.com/v4/letter/d/8dc957/32.png) [@Dalrain](https://forums.suse.com/u/Dalrain)\
**Post date:** [March 9, 2012, 6:21pm UTC](https://forums.suse.com/t/apache2-directoryindex-override/22305/4 "2012-03-09T18:21:31Z")

</div>

[QUOTE=smflood;2950]On 06/03/2012 15:04, Dalrain wrote:

In your /etc/apache2/httpd.conf.local try adding the following lines

\<Directory /srv/www/htdocs\>  
AllowOverride Indexes  
  
DirectoryIndex index.php index.html index.htm

[/QUOTE]

No dice, it would appear. Specifically, the server prefers index.html (not index.htm) - I think this is probably because DirectoryIndex is additive, so any directive appearing after the initial declaration is at a lower precedence. (Rather than overriding, that is.)

The first line apache would encounter is the following, which I’m guessing means it remains the first thing it looks for (from httpd.conf):

# List of resources to look for when the client requests a directory

DirectoryIndex index.html index.html.var

I think this might be a case where SuSEconfig needs to allow for precedence in the sysconfig dir.

---

<div class="post-metadata">

**Author:** ![Dalrain](https://avatars.discourse-cdn.com/v4/letter/d/8dc957/32.png) [@Dalrain](https://forums.suse.com/u/Dalrain)\
**Post date:** [March 9, 2012, 6:25pm UTC](https://forums.suse.com/t/apache2-directoryindex-override/22305/5 "2012-03-09T18:25:34Z")

</div>

Derp. Self replying because I got it now, in part due to your answer. It actually works if you just toss the index directive into a Directory container i.e.

\<Directory /srv/www/htdocs\>  
AllowOverride Indexes  
DirectoryIndex index.php index.html index.htm

Thank you for the response, Simon!

---

<div class="post-metadata">

**Author:** ![smflood](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/smflood/32/10576_2.png) [@smflood](https://forums.suse.com/u/smflood)\
**Post date:** [March 9, 2012, 6:53pm UTC](https://forums.suse.com/t/apache2-directoryindex-override/22305/6 "2012-03-09T18:53:29Z")

</div>

On 09/03/2012 16:34, Dalrain wrote:  
[color=blue]

> Derp. Self replying because I got it now, in part due to your answer.  
> It actually works if you just toss the index directive into a Directory  
> container i.e.
> 
> \<Directory /srv/www/htdocs\>  
> AllowOverride Indexes  
> DirectoryIndex index.php index.html index.htm  
> [/color]

Ah yes DirectoryIndex within the Directory would take precedence over  
the default configured via /etc/apache2/httpd.conf whereas having it  
outside is still cumulative though would apply to all directories  
(something to bear in mind if you want to access PHP-based sites from  
other directories).  
[color=blue]

> Thank you for the response, Simon![/color]

## No problem, glad you’ve now got it working.

Simon  
Novell/SUSE/NetIQ Knowledge Partner

* * *

## Do you work with Novell technologies at a university, college or school? If so, your campus could benefit from joining the Novell Technology Transfer Partner (TTP) program. See [novell.com/ttp](http://novell.com/ttp) for more details.
