Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing the index.html from url

Tags:

html

url

indexing

Ok, maybe a pretty dumb question but I can't find an answer on Google.

I am coding my site by hand. How do I make the index.html disappear from the url's? Do I use a piece of code in my html? Do I have to change my href's in my files?

Hope you guys can help!

EDIT: I've tried this with a .htaccess file

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

It does work, but all my links aren't working anymore. I discovered I had to remove all the index.html from the href's in my documents. But that would be a lot of work. Is there an other code for .htaccess that just hides index.html?

like image 551
David Hakkert Avatar asked Mar 18 '14 13:03

David Hakkert


2 Answers

A SIMPLE WAY TO DO THIS in Html:

(example in my case is a simple dual language site)

If your link looks like this:

<a href="index.html">Homepage</a>

You should change it to this:

<a href="/">Homepage</a>

If trying to link to another folder in your directory, like is my example:

<a href="en/index.html">English language</a>

You should change it to this:

<a href="en">English language</a>

Notice that "/" goes back to your root directory and automatically selects index.html, so that is why I used "en" for the English language site, because the name of the folder in that case is "en". You should also make sure that you have index.html in your English language folder, and not index-en.html.

like image 140
Darko Atanasov Avatar answered Sep 19 '22 20:09

Darko Atanasov


Apache has .htaccess files and mod_rewrite, In your .htaccess file, set:

DirectoryIndex index.html

You can also set this up in the Apache site config files too

You can specify a list of filenames, so if it doesn't find the first it moves to the next.

IIS has .config files

like image 43
vogomatix Avatar answered Sep 18 '22 20:09

vogomatix