Default index files - change order, DirectoryIndex

software development

#1

This may be an Apache setting, but is there a way to specify the order of index file names that the Web server looks for? Specifically, I would like my server to look 1st for index.php, followed by index.html. Currently, it is the reverse of that. For an example of what I mean, take a look at my Web site and watch what happens (I have a redirect from index.html to index.php) and would like to avoid this.

Of course, I could just remove index.html altogether, but I would prefer not to since I have references out there to /index.html.

Thanks,
Gabe

P.S. I did find this in the Knowledge Base:
https://panel.dreamhost.com/kbase/index.cgi?area=1780, but it does not explain how to change this order, if that’s even possible


#2

I haven’t tried it, but can’t you just add an .htaccess file in your domain directory with:

DirectoryIndex index.php index.html … and any others you want to add, like the example in the knowledge base?

I believe the order they’re listed in is the order they’ll be looked for.


#3

Thanks for the suggestion. Good idea, but this did not work. It resulted in an internal server error 500:

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request


#4

That’s odd… I thought you could over-ride that.

Maybe someone with a brain will reply, since I’ve proven myself useless. hehe :smiley:


#5

It most definitely is possible (I use it in several places for the same reason you do.). It sounds possible there might be something corrupt about the .htaccess file itself. Did you upload it or create it in place using vi or something? If you have a Mac or Dos linebreak in .htaccess it might not work. Is there anything else in .htaccess?

Just guessing! No brain here either :slight_smile:


#6

You might have to enable full CGI on the domain for this to work (long story as to why this might be the case; it’s primarily for historical reasons).


#7

Yes, I did try creating .htaccess file directly on server (via Pico, my text editor of choice).

How do I enable full CGI? Is it the edit HTTP section of the control panel?

[checkbox] “Enable CGI and run as user:”

If so, that’s already enabled.

If not, then how do I enable full cgi?

thanks,
gabe


#8

I figured out a good way to do this: I created a .htaccess file in top-level web directory with one line in it:

redirect /index.html http://www.gabeanderson.com/index.php

then i removed the index.html file with the redirect that i previously had in place. works like a charm! check it out:

http://www.gabeanderson.com/index.html

or

http://www.gabeanderson.com/


#9

That will work, but setting DirectoryIndex should work. Of course if you simply don’t have an index.html file at all, your index.php file should be read by default.


#10

thanks, will. directoryIndex is working for me now. i think maybe it didn’t work the first time because i copied a big list of possible files from the knowledge base. but with just one entry it works fine. so this is what i now have, and all is well:

DirectoryIndex index.php
redirect /index.html http://www.gabeanderson.com/index.php

thanks again, everyone.

-gabe