Removing the index.html from url

2019-03-10 16:41发布

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?

6条回答
够拽才男人
2楼-- · 2019-03-10 17:22

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

查看更多
放荡不羁爱自由
3楼-- · 2019-03-10 17:23

mod_rewrite module is responsible for all the rewriteEngine. Check on your server whether is module is present and enable.

查看更多
劳资没心,怎么记你
4楼-- · 2019-03-10 17:34

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.

查看更多
够拽才男人
5楼-- · 2019-03-10 17:34

Simply don't type the index.html in your browser and don't advertise it as such.

You can set the 'default document' on the web server (whichever you happen to be using) to serve 'index.html' in the absence of a file part. This way, someone going to http://www.mysite.com would be served http://www.mysite.com/index.html

查看更多
聊天终结者
6楼-- · 2019-03-10 17:35

I think this is configured in IIS when you deploy the site, I'm not to sure on it but I'm sure you can specify a start point that your URL will use when you just enter the UL, that implies the Index.html page.

Sorry I'm not too helpful here, hopefully it will point you in the right direction.

Often these things such as Apache or IIS have this set up already, and it looks for the Inde.html, Index.php first when you just put your URL in.

查看更多
叼着烟拽天下
7楼-- · 2019-03-10 17:38

Change the link that goes to your homepage to the website address. You may have:

<a href="index.html">Link Here</a>

Change that to:

<a href="http://www.domain.com">Link</a>

Or try this

查看更多
登录 后发表回答