Setting a default index page using .htaccess

By default our servers will look for (in order) a file by the name of index.html, index.cgi, index.php, index.htm, default.htm or home.htm in a given directory and will load the first file it finds as the directory's (or site's) index or "homepage". If you wish to use an alternate file name as a default index page, this can be done by adding the following directive to a .htaccess file stored either in your public_html directory (if you wish the directive to be in effect for your your entire site) or in a specific folder:

DirectoryIndex filename.ext

For example if you wish the default index page in a given directory to be "default.php", you would place a .htaccess file in that folder containing the following line:

DirectoryIndex default.php

Things to Note

You can specify multiple filenames and the server will look for them in the order you specify and set the first valid filename found as the directory's index page. If you intend on setting a non-standard index page as your site's main index page you'll likely want to include more standard index filenames along with your custom name so that you will be able to use standard index files such as index.html or index.php in subdirectories without having to add separate .htaccess files.

DirectoryIndex page1.html index.html index.php index.htm

With the directive above in place the server will first look for a file named "page1.html" and if found, will load it as the directory index. If no file by that name exists in a given directory, it will look for (in order) files named index.html, index.php and index.htm and load the first file it finds as the index page.

  • 1982 Bu dökümanı faydalı bulan kullanıcılar:
Bu cevap yeterince yardımcı oldu mu?

İlgili diğer dökümanlar

How to redirect a page to another page or website using .htaccess?

If a page on your website no longer exists and you want to redirect it to your new page or...

How to create a user-friendly URL using .htaccess?

If your website is using a long URL like example.com/files/folder/sitemap.html, you can change it...

Preventing bandwidth theft using .htaccess

While all HostRocket plans include plenty of bandwidth (transfer) nobody ever has enough...

How do I re-direct non-https traffic to the https version of the website?

With the latest cPanel version, there is a 'Force HTTPS Redirect' option in the 'Domains'...

Redirection using .htaccess

Most websites are constantly changing "works in progress" and as one updates, rearranges and...