20

I have website http://mywebsite.com If I hit this URL it take index.php and index.html as default page. How can I make home.php as default page. I have tried this but not working by placing following code inside .htaccess file of public_html

DirectoryIndex home.php index.html index.php
CodeManiac
  • 974
  • 8
  • 34
  • 56

4 Answers4

31

You just need home.php in your DirectoryIndex to make it works. Remember that this is using in .htaccess file of your root project:

DirectoryIndex home.php
Eli
  • 14,779
  • 5
  • 59
  • 77
  • 5
    It applies to all sub folders. I want to apply only to the root folder only. – CodeManiac Apr 03 '13 at 05:44
  • NB: This code will apply for all your sub folders. Use the below code instead of 'DirectoryIndex' . >>>>>>>> RewriteEngine on RewriteRule ^$ /yourfile.html [L] – Nikz Nov 13 '19 at 10:28
13

You need AllowOverride +Indexes in your httpd.conf to be able to use DirectoryIndex in .htaccess.

Barring that, the absolutely easiest way to redirect (without the root access to Apache config and modules) is putting this as index.html:

<!doctype html>
<html>
  <head>
    <meta http-equiv="Refresh" content="0; url=home.php">
  </head>
  <body>
  </body>
</html>
Amadan
  • 191,408
  • 23
  • 240
  • 301
  • But which way is better? Which one is faster? Isn't it better for the user, to go directly to the home.html instead of being redirected from one url to another? – Przemysław Niemiec Jul 27 '20 at 18:01
  • 1
    @PrzemysławNiemiec Yes, it is. The second solution is the work-around for when you have no control of Apache, as written in the answer. – Amadan Jul 27 '20 at 18:03
4

DirectoryIndex directive applies to all subfolders, if you want set diffrent files for each directories, you can use mod-rewrite.

To set /file.html as root directory handler, you can use this at the top of your htaccess :

RewriteEngine on
RewriteRule ^$ /file.html [L]

To set a diffrent file as index for a subfolder, use this :

RewriteEngine on
RewriteRule ^subfolder/$ /myfile.html [L]
Amit Verma
  • 40,709
  • 21
  • 93
  • 115
-2

Just try to rewrite /index.html and /index.php into /home.php

Options +FollowSymlinks
RewriteEngine on

RewriteCond %{REQUEST_URI} ^/index\.(html|php)
RewriteRule ^(.*) /home.php