Frank Eno
Frank Eno

Reputation: 2649

How to open an index page into a subdirectory without adding /index.html

Simple question, let's pretend I have the following path:

http://example.com/subdir/index.html

I would like to be able to open that index.html page by typing this in the browser:

www.example.com/subdir

and hit enter to have the browser load its included index.html page.

Is that possible?

My goal is to have a few subdirectories with the same root domain (example.com) and be able to open the index.html pages of each subdirectory without having to add /index.html at the end.

Thanks so much!

Upvotes: 2

Views: 5183

Answers (2)

Mohammed Elhag
Mohammed Elhag

Reputation: 4302

For sub folders only put this in main root .htaccess file :

 RewriteEngine On
 RewriteRule ^(.*)/index([\.html]*)$ /$1 [R=302,L] 

For entire website change it to this :

 RewriteEngine On
 RewriteRule ^(.*)index([\.html]*)$ /$1 [R=302,L] 

So , any request with index or index.html will be removed .

Note : clear your browser cache then test it , if Ok change 302 to 301 to get permanent redirection

Upvotes: 1

Kevin HR
Kevin HR

Reputation: 249

If you server is running Apache, just create an .htaccess file (if you haven't already) and add this line at the top of the file:

DirectoryIndex index.html

Upvotes: 0

Related Questions