88

I would like to change the default web page that shows up when I browse my site. I currently have a reporting program running, and it outputs a file called index.html. I cannot change what it calls the file. Therefore, my landing page must be called something else. Right now, when I browse my site it takes me to the reporting page.

From what I see, whatever you call index.html it will pull that up as your default. I want to change that to landing.html. How do I do this?

I am a folder (Folding @ Home). The reporting program is HFM.net. HFM can output an html file with my current folding statistics. It names the html file index. I do not want that to be my default home page. I would like a menu-like landing where I can choose if I want to see my stats, or something else. The website is at /home/tyler/Documents/hfm/website (landing.html and hfm's index.html are here). Apache2 is in its default directory.

I'm also running Ubuntu 13.04.

Tyler Montney
  • 1,402
  • 1
  • 17
  • 25
  • By default, DirectoryIndex is index.html but the file is absent. Just create index.html in /var/www/html and you will see your contents. – Leon Aug 17 '18 at 01:57

5 Answers5

110

I recommend using .htaccess. You only need to add:

DirectoryIndex home.php

or whatever page name you want to have for it.

EDIT: basic htaccess tutorial.

  1. Create .htaccess file in the directory where you want to change the index file.
  • no extension

  • . in front, to ensure it is a "hidden" file

    Enter the line above in there. There will likely be many, many other things you will add to this (AddTypes for webfonts / media files, caching for headers, gzip declaration for compression, etc.), but that one line declares your new "home" page.

  1. Set server to allow reading of .htaccess files (may only be needed on your localhost, if your hosting servce defaults to allow it as most do)

Assuming you have access, go to your server's enabled site location. I run a Debian server for development, and the default site setup is at /etc/apache2/sites-available/default for Debian / Ubuntu. Not sure what server you run, but just search for "sites-available" and go into the "default" document. In there you will see an entry for Directory. Modify it to look like this:

<Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
</Directory>

Then restart your apache server. Again, not sure about your server, but the command on Debian / Ubuntu is:

sudo service apache2 restart

Technically you only need to reload, but I restart just because I feel safer with a full refresh like that.

Once that is done, your site should be reading from your .htaccess file, and you should have a new default home page! A side note, if you have a sub-directory that runs a site (like an admin section or something) and you want to have a different "home page" for that directory, you can just plop another .htaccess file in that sub-site's root and it will overwrite the declaration in the parent.

Rohit Gupta
  • 4,022
  • 20
  • 31
  • 41
PlantTheIdea
  • 16,061
  • 5
  • 35
  • 40
  • How do I use htaccess? My landing.html file is not in the same directory. – Tyler Montney Oct 11 '13 at 16:15
  • Hmmm... so what I'm supposed to do is create a file named ".htaccess" in my root directory? My root directory is something else as I changed it in the httpd.conf (and I added an "Include httpd.conf" in apache2.conf. Would that be the root directory to which you're referring? Check my edit in the original post for my situation. – Tyler Montney Oct 11 '13 at 16:40
  • when i refer to root directoy, i mean the root directory of the **site** (in your case, `/home/tyler/Documents/hfm/website`), not ur comp. edited the verbiage in my answer, i can see how that could be misunderstood. – PlantTheIdea Oct 11 '13 at 17:24
  • did u reload the server? and also, since u did a custom site location, did u create a different enabled site than "default"? because that is the one u need to mod, if so. – PlantTheIdea Oct 11 '13 at 18:05
  • Actually everything is working now. Any idea how I would reference another html file? I'm trying to do it within an image. I'm getting a 404 error. – Tyler Montney Oct 11 '13 at 18:34
  • you might want to pose this as a separate question, with more explanation and code provided. – PlantTheIdea Oct 11 '13 at 19:46
  • service should be singular in the restart/reload command line – scotru May 16 '14 at 18:02
  • Instead of `service apache2 reload && sudo service apache2 restart` you can just pass `service apache2 restart`. When you restart Apache it reloads itself automatically, just as on normal service start. – kazy Sep 10 '14 at 23:27
  • Instead of using restart you can use graceful (http://httpd.apache.org/docs/2.2/stopping.html#graceful) – Matteo Jul 20 '15 at 06:59
  • After some headaches, I had to set AllowOverride to `All` for getting this working. Btw, the file you have to edit is not such `/etc/apache2/sites-available/default` but `/etc/apache2/apache2.conf` – Akronix Jan 06 '16 at 21:46
  • Can you please explain what each line is doing? The suggested edits to the configuration file are causing errors for me. – randy Jan 05 '20 at 03:54
26

You can also set DirectoryIndex in apache's httpd.conf file.

CentOS keeps this file in /etc/httpd/conf/httpd.conf Debian: /etc/apache2/apache2.conf

Open the file in your text editor and find the line starting with DirectoryIndex

To load landing.html as a default (but index.html if that's not found) change this line to read:

DirectoryIndex  landing.html index.html
botheredbybees
  • 582
  • 6
  • 14
1

I had a similar problem. When providing http://server/appDirectory I got a directory listing instead of index.html even though I had

<IfModule dir_module>
    DirectoryIndex index.php index.html 
</IfModule>

in my httpd.conf file.

My solution was to uncomment the

LoadModule setenvif_module modules/mod_setenvif.so

line in httpd.conf

Apache version: 2.4

Mark Ainsworth
  • 811
  • 8
  • 24
1

In Ubuntu you can add in file:

/etc/apache2/mods-enabled/dir.conf

line

DirectoryIndex myhomepage.htm

and then restart apache service

sudo systemctl restart apache2

  • 1
    Hi, this is a comment, not an helpful answer. bu sure to read [this help page](https://stackoverflow.com/help/how-to-answer) – pierpy Dec 25 '22 at 06:37
  • Why is that? This is the only solution for me. And I shared it. I probably didn't explain it well. – Alex Sidler Dec 29 '22 at 05:46
  • Because you say "now it doesn't help", and there is already an accepted answer with 107 upvotes . So, looks like a comment, not an aswer that addresses original question :-). I wanted to help you better understand stackoverflow rules! – pierpy Dec 29 '22 at 07:51
0

In Unbuntu, you can update the default page on a site-by-site basis with the site config files eg:

/etc/apache2/sites-available/your.domain.conf

Same syntax for the key line in the file, eg mine is;

DirectoryIndex default.htm index.htm

Then don't forget to enable and reload:

sudo a2ensite your.domain.conf
sudo systemctl reload apache2