2

I used the solution given on this link for this.

        DirectoryIndex home.php

but it applies to root directory and its subdirectories. However, I need a solution that set default page for only root directory, not for the subfolders. I looked around a lot, but couldn't find one.

Any suggestion is appreciated. Thanks.

Community
  • 1
  • 1
A J
  • 3,970
  • 14
  • 38
  • 53
  • See this answer. It's on your link as well..... http://stackoverflow.com/questions/15779198/how-to-make-default-page-home-php-instead-of-index-html-and-index-php#answer-15779251 – Refilon Mar 29 '16 at 09:45
  • 1
    @Refilon, I cannot use this solution, as I want open a custom page when a user access my website. He/she has to select an option on this page and after that, he/she will be redirected to Index page. However, this code is affecting subfolders as well. – A J Mar 29 '16 at 09:48

1 Answers1

3

I need a solution that set default page for only root directory, not for the subfolders

You can do this using a rewrite rule in root .htaccess:

RewriteEngine On

RewriteRule ^/?$ home.php [L]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Thanks Anubhava, can `DirectoryIndex home.php` be modified in some way to solve this problem? – A J Mar 29 '16 at 09:56
  • 1
    `DirectoryIndex` cannot be conditional. Better to set `DirectoryIndex` to some generic handler like `DirectoryIndex index.html index.php` and use this rule for document root directory. – anubhava Mar 29 '16 at 09:58
  • 1
    Ok, Thanks again for the solution, it is working correct. – A J Mar 29 '16 at 10:09
  • Thank you @anubhava Can you please explain what is this part exactly doing: ^/?$ – Mohamed Anis Dahmani Jul 27 '17 at 06:38