2

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!

3
  • how about "www.example.com/subdir/"? Commented Oct 7, 2017 at 5:19
  • i tried but it doesn’t work :( Commented Oct 7, 2017 at 5:24
  • try this: fvimagination.com/testhtml the testhtml subdirectory has an index.html page inside, but the browser doesn't find that page. May it be because of my root website which is in WordPress? .htacess issue, maybe? Commented Oct 7, 2017 at 5:28

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

4 Comments

it doesn't work yet, here's my .htaccess file: DirectoryIndex index.html # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress maybe it doesn't work because of WordPress
@fvimagination Where have you put this htaccess file. In root directory or in subdir ?
@siddharth root directory. so you mean that i have to create a new .htaccess with DirectoryIndex index.html and upload it in my subdir?
yes you have to place this htaccess in subdir. Give it a try

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.