您应该使用 .htm 还是 .html 文件扩展名? 有什么区别,哪个文件是正确的?

发布于 2024-07-29 04:34:57 字数 1432 浏览 4 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

坦然微笑 2024-08-05 04:34:57

简短的回答

没有。 它们是完全相同的。

长答案

.htm 和 .html 完全相同,并且以相同的方式工作。 选择取决于个人喜好,只要您与文件命名一致,就不会出现问题。

根据 Web 服务器的配置,其中一种文件类型将优先于另一种文件类型。 这不应该是一个问题,因为您不太可能将index.htm 和index.html 放在同一个文件夹中。

我们始终使用较短的 .htm 作为文件名,因为文件扩展名通常为 3 个字符长。

更多信息:http://www.sightspecic.com/~mosh/ WWW_FAQ/ext.htmlhttp://www.sightspecic.com/ ~mosh/WWW_FAQ/ext.htm

我想我应该在此处添加这部分:
.htm 和 .html 文件之间有一处细微的差别。 考虑服务器中的路径,例如:mydomain.example/myfolder。 如果您在该文件夹中创建一个 index.htm 文件,然后像这样打开它:mydomain.example/myfolder/,它会发疯并吐出您的文件。在您的服务器中,用 .htm 文件描述错误的图像
但是如果您在其中创建一个 index.html 文件并在浏览器中打开该目录,它将加载该文件。
我在我的 VPS 上测试了这个并发现了这个
也许您可以以某种方式将服务器设置为默认加载index.htm 文件,但我猜.html 文件是浏览器在每个目录中打开的默认文件类型。

The short answer

There is none. They are exactly the same.

The long answer

Both .htm and .html are exactly the same and will work in the same way. The choice is down to personal preference, provided you’re consistent with your file naming you won’t have a problem with either.

Depending on the configuration of the web server, one of the file types will take precedence over the other. This should not be an issue since it’s unlikely that you’ll have both index.htm and index.html sitting in the same folder.

We always use the shorter .htm for our file names since file extensions are typically 3 characters long.

AND MORE ON: http://www.sightspecific.com/~mosh/WWW_FAQ/ext.html or http://www.sightspecific.com/~mosh/WWW_FAQ/ext.htm

I think I should add this part here:
There is one single slight difference between .htm and .html files. Consider a path in your server like: mydomain.example/myfolder. If you create an index.htm file inside that folder and you open that like this: mydomain.example/myfolder/, it will go crazy and spit out your files as it is in your server,An image describing the bug with .htm files
but if you create an index.html file in there and open that directory in your browser, it will load that file.
I tested this on my VPS and found this.
Maybe you could somehow set your server to load index.htm files by default, but I guess the .html file is the default file type for browsers to open in each directory.

灼痛 2024-08-05 04:34:57

两者都不!

如果你问; “网站访问者更喜欢输入什么,htm 还是 html” - 最好为他们提供一个没有扩展名的漂亮的描述性 URL。 如果他们习惯访问 yoursite/contact.html,而您将其更改为 yoursite/contact.php,那么您就破坏了该链接。 如果您使用您的网站/联系人/,那么切换技术时就没有问题。

Neither!

If you're asking; "what would a website visitor rather type, htm or html" - it's much better to give them a nice descriptive URL with no extension. If they get used to going to yoursite/contact.html and you change it to yoursite/contact.php you've broken that link. If you use yoursite/contact/ then there's no problem when you switch technology.

淤浪 2024-08-05 04:34:57

.html 始终用于新文件。 .htm 是对 dos 时代的倒退。

.html always for new files. .htm is a throwback to dos days.

池予 2024-08-05 04:34:57

.html - DOS 已经消亡很长时间了。 但最终并没有多大区别。

.html - DOS has been dead for a long time. But it doesn't really make much difference in the end.

夜灵血窟げ 2024-08-05 04:34:57

同样的事情.. 根本没有区别... htm 是在只有 3 个字母扩展名很常见的时代使用的。

Same thing.. makes no difference at all... htm was used in the days where only 3 letter extensions were common.

还在原地等你 2024-08-05 04:34:57

如果您打算将文件放在仅支持 8.3 命名约定的计算机上,则应将扩展名限制为 3 个字符。

否则,最好选择更具描述性的 .html 版本。

If you plan on putting the files on a machine supporting only 8.3 naming convention, you should limit the extension to 3 characters.

Otherwise, better choose the more descriptive .html version.

甜心小果奶 2024-08-05 04:34:57

我想现在有点太晚了,但是唯一能产生影响的是当您在 MS Outlook 上设置 HTML 签名时(甚至是 2010 年)。 它只是无法处理 .html 扩展名,只能处理 .htm

I guess it's a little too late now however the only time it does make a difference is when you set up HTML signatures on MS Outlook (even 2010). It's just not able to handle .html extensions, only .htm

雨后咖啡店 2024-08-05 04:34:57

在功能和支持方面是相同的。 (大多数操作系统都可以识别,大多数搜索引擎都可以识别)

对于我的日常使用,我选择 .htm,因为它的打字时间缩短了 25%。

It's the same in terms of functionality and support. (most OS recognize both, most Search Engines recognize both)

For my everyday use, I choose .htm because it's shorter to type by 25%.

时光礼记 2024-08-05 04:34:57

这里有一些值得深思的地方。

例如,如果您一直在网站上使用所有 .htm 文件,而现在您更改了正在使用的编辑器,并且新编辑器正在输出带有 .html 扩展名的所有文件。 当您将网站重新发布到服务器时,在我看来,您确实可能会损害您的 SEO 位置/排名,因为网络中的许多链接(包括 Google)正在寻找 .htm 而不是 .htm同一页面的新 .html。 这假设您仍然使用旧编辑器中的相同页面名称,这是有意义的。

不管怎样......我的观点是,小心不要失去你建立的链接汁。 所以我想在这个例子中,有一个理由坚持使用 .htm...但除此之外,正如其他人提到的那样,它们似乎是相同的。

如果我错了,请纠正。

我之所以提到这一切,是因为这就是我正在做的事情,当我想到我可能会用新编辑器破坏网站搜索引擎优化时。

原来的编辑器是 MS Front Page,它总是输出 .htm,现在已经死了,而新的编辑器“90 Second Web Builder 9”输出所有 .html 文件......幸运的是,他们一定已经考虑到了这一点,并且包括了一种方法将输出扩展名更改回 .htm

无论如何,这是我的 2 美分...希望它对某人有帮助..

Here is some food for thought.

If you had been using all .htm files on your website and now, for example, you have changed the editor that you are using, and your new editor is outputting all your files with the .html extension. When you re-publish your site to the server, it would seem to me that you could really hurt your SEO position/ranking as many of the links out there in the web, including Google, that were looking for the .htm and not the new .html for that same page. This assumes that you are still using the same page names from your old editor which would make sense.

Anyway... My point is, be careful not to loose that link juice you have build up. So I guess in this example, there is a reason to stick with .htm... But other then that as mentioned by everyone else they seem to be the same.

Please correct if I'm wrong.

The reason I mention all this is because this is what I was in the process of doing when it occurred to me I may be damaging the site SEO with the new editor.

The original editor was MS Front Page, which always outputted .htm, dead now, and the new editor "90 Second Web Builder 9" which outputs all .html files... Luckily, they must have thought about this and they included a way to change the output extension back to .htm

Anyway, that's my 2 cents... hope it helps someone..

夏见 2024-08-05 04:34:57

由于如今,计算机广泛支持任何长度的文件类型,因此现在的选择只是个人的。 早在 Windows 早期,仅支持 3 个字母,您必须使用 .htm,但现在不再需要了。

Since nowadays, computers support widely any length as file type, the choice is now only personal. Back in the early days of Windows where only 3 letters where supported, you had to use .htm, but not anymore.

把时间冻结 2024-08-05 04:34:57

简而言之,它们是完全相同的。 如果您注意到 URL 的结尾,有时您会看到 .htm,有时您会看到 .html。 它仍然指的是超文本标记语言。

In short, they are exactly the same. If you notice the end of the URL, sometimes you'll see .htm and other times you'll see .html. It still refers to the Hyper-Text Markup Language.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文