ID-100115201

Some times we want a different page than our website’s normal homepage to load when a visitor gets to the site.  This can be for various reasons but especially if you have a landing page for a marketing purposes.  During the SOPA fight last year, a lot of webmasters ‘blacked out’ their site for this purposes – ourselves included. So how would you temporarily change which page on your site loads by default, without having to rename files, edit your menu, etc?

You do it using your .htaccess file.

The below command will set the default page your website shows to whatever you specify. For example if you want your website to show the index.html file as default:

DirectoryIndex index.html

Or a file with a completely different name as the default page for your website and every directory.

DirectoryIndex business.html

You can even load an image as default, or even a movie:

DirectoryIndex cool.mov

Or even specify a string (multiple files) so that it will try to load the first one – or if that file is not found, then the next, and so on. So with the below line it would try to load splash.html, then if that wasn’t there index.cgi, and if that wasn’t there index.pl, and so on.

DirectoryIndex splash.html index.cgi index.pl default.htm

If it can’t find the file you specify it will revert to a directory listing of the files in that folder.

Careful when playing around with movie files though.  Not all browsers can play movie files natively, and then only a few formats. Rather embed a video player in a single page and have the move load through that.