.htm 或 .html 扩展名 - 哪个是正确的,有什么不同?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/138953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 22:24:27  来源:igfitidea点击:

.htm or .html extension - which one is correct and what is different?

htmlnaming-conventionsfilenames

提问by user21067

When I save a file with an .htm or .html extension, which one is correct and what is different?

当我保存带有 .htm 或 .html 扩展名的文件时,哪个是正确的,哪些不同?

回答by William Keller

Neither is wrong, it's a matter of preference. Traditionally, MS software uses htmby default, and *nix prefers html.

两者都没有错,这是一个偏好问题。传统上,MS 软件htm默认使用,*nix 更喜欢html.

As oded pointed out below, the .htm tradition was carried over from win 3.xx, where file extensions were limited to three characters.

正如 oded 在下面指出的那样,.htm 传统是从 win 3.xx 继承而来的,其中文件扩展名限制为三个字符。

回答by ddaa

Mainly, the number of characters is different.

主要是字符数不同。

".htm" smells of Microsoft operating systems where the file system historically limited file name extensions (the part of the file name after the dot) to 3 characters.

“.htm”有微软操作系统的味道,其中文件系统历来将文件扩展名(点之后的文件名部分)限制为 3 个字符。

".html" smells of Un*x operating systems that did not have this limitation and that were used for all the serious internet work at the time.

“.html”散发着 Un*x 操作系统的味道,这些操作系统没有这个限制,当时用于所有严肃的互联网工作。

Pragmatically, the two are equivalent.

实际上,两者是等价的。

The difference is cultural. ".html" is regarded by some as more correct. The same people tend to look down at Microsoft operating systems and regard ".htm" as unsightly reminder of their limitations.

区别在于文化。“.html”被一些人认为更正确。同样的人倾向于看不起 Microsoft 操作系统,并将“.htm”视为其局限性的难看提醒。

回答by ConroyP

When you save the file locally, the difference doesn't matter - your local system will likely treat the two file extensions as interchangeable for loading by your browser. The reason for it is that historically Windows-based systems used 3 letter extensions (htm) and Unix-based systems the 4 letters (html).

当您在本地保存文件时,区别并不重要 - 您的本地系统可能会将这两个文件扩展名视为可互换以供浏览器加载。其原因是历史上基于 Windows 的系统使用 3 个字母扩展 ( htm) 而基于 Unix 的系统使用 4 个字母 ( html)。

On a server-side, there may be some differences when it comes to serving default filenames:

在服务器端,在提供默认文件名方面可能存在一些差异:

The one situation in which there may be a difference between the two extensions is that of a server's default filenames. When a URL that does not specify a filename is requested from a server, such as http://www.domain.dom/dirname/, the server returns a file from the requested URL that matches a default filename. Examples of common default filenames include "index.html," "index.htm," "default.html," "default.htm," etc. However, an administrator can make the server's default filename anything he/she so desires.

Note that servers are often configured with more then one default filename.

两种扩展名之间可能存在差异的一种情况是服务器的默认文件名。当从服务器请求未指定文件名的 URL 时,例如http://www.domain.dom/dirname/,服务器从请求的 URL 返回一个与默认文件名匹配的文件。常见默认文件名的示例包括“ ” index.html、“ ” index.htm、“ ” default.html、“ ” default.htm、“等。但是,管理员可以将服务器的默认文件名设为他/她想要的任何名称。

请注意,服务器通常配置有多个默认文件名。

So if you have any level of control over your server's default filenames, then this shouldn't be an issue.

因此,如果您对服务器的默认文件名有任何级别的控制,那么这应该不是问题。

回答by Gene

Personally I prefer the .html but as other have said both will work.

我个人更喜欢 .html 但正如其他人所说,两者都可以。

Just make sure you only use one. Never both on the same site!link to mypage.html is not the same as link to mypage.htm

只要确保你只使用一个。永远不要在同一个网站上!指向 mypage.html 的链接与指向 mypage.htm 的链接不同

回答by Konrad Rudolph

Also notice that as part of a URI, the file extension doesn't play any role. In fact, it isn't even a file extension, it just looks like one. The type of the resource identified by a URI is notencoded in its name. Instead, it is decided by the Content-TypeHTTP header field. It's completely legitimate (but perhaps a bit stupid) to deliver a bitmap picture as myimage.htmland conversely, to deliver an HTML page as index.png. This is also the reason why it is argued that file extensions shouldn't be part of URIs at all.

另请注意,作为 URI 的一部分,文件扩展名没有任何作用。事实上,它甚至不是一个文件扩展名,它只是看起来像一个。由 URI 标识的资源类型在其名称中编码。相反,它由Content-TypeHTTP 标头字段决定。将位图图片myimage.html作为index.png. 这也是为什么有人认为文件扩展名根本不应该是 URI 的一部分的原因。

Sir Tim Berners-Lee elaborates on this in Hypertext Style: Cool URIs Don't Change.

Tim Berners-Lee 爵士在Hypertext Style: Cool URIs Don't Change 中详细阐述了这一点。

回答by Tundey

I use .htm. Less typing I guess. Or perhaps it's my windows-bias.

我使用.htm。我猜打字少了。或者也许这是我的 Windows 偏见。

回答by WalkingRandomly

They are completely interchangeable. If I understand the history properly then in the beginning the correct extension was .html but when Windows 95 came along it could only cope with 3 character extensions.

它们完全可以互换。如果我正确理解历史,那么一开始正确的扩展名是 .html,但是当 Windows 95 出现时,它只能处理 3 个字符的扩展名。

So .html is correct according to some standard or other but in practice it doesn't matter (most of the time...have just done a quick google search and found the following)

因此,根据某种标准或其他标准,.html 是正确的,但实际上这无关紧要(大多数情况下...刚刚进行了快速的谷歌搜索并找到了以下内容)

There is one area of concern though, most host servers will require your default starting page to be named as "index.html" and not as "index.htm"

但是,有一个方面值得关注,大多数主机服务器将要求您的默认起始页面命名为“index.html”而不是“index.htm”

回答by Rory

Personally I prefer .html, since the name is "Hypertext markup language". .htm was used because certain legacy versions of windows could not have more than 3 characters in the file name extension

我个人更喜欢 .html,因为它的名字是“超文本标记语言”。使用 .htm 是因为某些旧版 Windows 的文件扩展名不能超过 3 个字符

回答by Paul Whelan

Both are correct back in the past file extensions had to be a maximum of 3 characters long.

两者在过去都是正确的,文件扩展名的长度最多为 3 个字符。

http://en.wikipedia.org/wiki/Filename_extension

http://en.wikipedia.org/wiki/Filename_extension

回答by Paul Whelan

Both are working as same,but For the technical and non technical reference please find out here, http://www.sightspecific.com/~mosh/www_faq/ext.html

两者的工作方式相同,但有关技术和非技术参考,请在此处找到, http://www.sightspecific.com/~mosh/www_faq/ext.html