One of thesitewizard.com's visitors wrote to ask me how he could make a certain page the default web page that is displayed when his visitors go to his site's domain name. For example, he wanted his visitors to see the web page located at "http://www.example.com/home2.html" when they typed his domain name, http://www.example.com/. This article explains how this can be accomplished.
This article is for those who already have a domain name. If you are here trying to find out how to get your own domain name, please read How to Register Your Own Domain Name instead.
If you are not hosted on a Apache web server on a commercial web host, chances are that only the option given in the section "The Easiest Way" is available to you. Free web hosts rarely allow sites hosted on them to modify the web server configuration.
If your web page is just a normal HTML file, like (say) "home2.html", the easiest way is to simply rename it to "index.html". Most (if not all) web servers will automatically serve that file when your visitors go to your domain without any filename (like "http://www.example.com/").
Using a standard name like "index.html" not only solves the problem, but it may also help when search engines
http://www.example.com/ has an identical page to
Since this is the case for most websites, an intelligent search engine can simply regard it as the same page, and not
treat it as a duplicate, causing all sorts of duplicate
This should be the method you use, unless you have special reasons for not wanting the standard filename.
For some people, the above method is not possible. For example, you may want
http://www.example.com/special.php script instead of an ordinary web page.
If your site is hosted on an Apache server, you should create an text file using a plain ASCII or programmer's editor with the following line:
You should of course use the actual file name you want as the directory index instead of "special.php".
In addition, if you want (say) the web server to serve the "special.php" file by default, but if it's not present, to display the "index.html" file, do the following:
You can add other filenames to that list if you wish. Separate each filename from the others with a space.
Some things to note:
You should not use a word processor to create such a file. Do not use Word, Office, OpenOffice or even Wordpad. If you are running Windows, use Notepad, which can be found somewhere in the Accessories folder in your Start menu.
Do not use capital letters (uppercase) or spaces in your filenames. These characters cause numerous problems for new webmasters and their websites. If you must use them, make sure you always use the same case and encode the spaces with their "%" equivalent every time you refer to that file or URL. If you don't understand the previous sentence, don't use capital letters and spaces.
Save the file as ".htaccess". If you use Notepad, be sure to include the quotation marks around the filename, or Notepad will add a .txt extension to your file without telling you. Notice that the name begins with a full stop (period) and is entirely in small letters (lowercase). Do not change the name.
If you find that you already have an existing ".htaccess" file in the directory you're uploading to, do not simply overwrite it. Download the existing .htaccess file, and add the above line to the end of the file. Alternatively, if there is already a "DirectoryIndex" directive in the file, replace it with the one given above.
The .htaccess is the configuration file for your website. If you make any mistake with the file, your entire website may be rendered completely inaccessible. As such, if your site already has an existing .htaccess file, make sure you back it up before modifying it.
In the event that you inadvertently take down your website, you can easily solve it by either deleting the .htaccess file that you just uploaded or restoring the old version that you backed up (depending whether there was an old version).
With the above steps, you have changed the name of the default web page for your domain when it is requested without an additional folder name or filename.
This article can be found at https://www.thesitewizard.com/apache/change-default-page-for-domain.shtml
Do you find this article useful? You can learn of new articles and scripts that are published on thesitewizard.com by subscribing to the RSS feed. Simply point your RSS feed reader or a browser that supports RSS feeds at https://www.thesitewizard.com/thesitewizard.xml. You can read more about how to subscribe to RSS site feeds from my RSS FAQ.
This article is copyrighted. Please do not reproduce or distribute this article in whole or part, in any form.
It will appear on your page as: