从网址中删除index.html [英] Removing the index.html from url

查看:71
本文介绍了从网址中删除index.html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,也许是一个很愚蠢的问题,但我在Google上找不到答案.

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

我正在手工编码我的网站.如何使index.html从网址中消失?我在html中使用一段代码吗?我必须更改文件中的href吗?

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?

希望你们能提供帮助!

我已经尝试过使用.htaccess文件

I've tried this with a .htaccess file

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

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

它确实起作用,但是我所有的链接都不再起作用.我发现必须从文档的href删除所有index.html.但这将是很多工作. .htaccess是否还有其他代码隐藏了index.html?

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?

推荐答案

在HTML中执行此操作的简单方法:

(在我的例子中是一个简单的双语网站)

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

如果您的链接如下所示:

If your link looks like this:

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

您应该将其更改为此:

<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>

您应该将其更改为此:

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

请注意,"/"返回到您的根目录并自动选择index.html,因此这就是我在英语站点中使用"en"的原因,因为在这种情况下,文件夹的名称为"en".您还应确保英语文件夹中有index.html,而不是index-en.html.

这篇关于从网址中删除index.html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆