.htm 或 .html 扩展名 - 哪一个是正确的,有什么不同?
当我保存扩展名为 .htm 或 .html 的文件时,哪个是正确的,有什么不同?
When I save a file with an .htm or .html extension, which one is correct and what is different?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
两者都没有错,只是偏好问题。 传统上,MS 软件默认使用
htm
,而 *nix 更喜欢html
。正如下面所指出的,.htm 传统是从 win 3.xx 延续下来的,其中文件扩展名仅限于三个字符。
Neither is wrong, it's a matter of preference. Traditionally, MS software uses
htm
by default, and *nix prefershtml
.As oded pointed out below, the .htm tradition was carried over from win 3.xx, where file extensions were limited to three characters.
当您在本地保存文件时,差异并不重要 - 您的本地系统可能会将这两个文件扩展名视为可互换,以便由浏览器加载。 其原因是历史上基于 Windows 的系统使用 3 个字母扩展名 (
htm
),而基于 Unix 的系统使用 4 个字母 (html
)。在服务器端,提供默认文件名:
因此,如果您对服务器的默认文件名有任何级别的控制,那么这应该不是问题。
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
).On a server-side, there may be some differences when it comes to serving default filenames:
So if you have any level of control over your server's default filenames, then this shouldn't be an issue.
主要是字数不同。
“.htm”带有 Microsoft 操作系统的味道,其中文件系统历来将文件扩展名(点后的文件名部分)限制为 3 个字符。
“.html”带有 Un*x 操作系统的味道,该操作系统没有此限制,并且用于当时所有严肃的互联网工作。
从实用上讲,两者是等效的。
差异在于文化。 有些人认为“.html”更正确。 这些人往往看不起微软操作系统,并认为“.htm”是对其局限性的不雅观提醒。
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.
".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.
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.
另请注意,作为 URI 的一部分,文件扩展名不起任何作用。 事实上,它甚至不是一个文件扩展名,只是看起来像一个。 由 URI 标识的资源类型未编码在其名称中。 相反,它由
Content-Type
HTTP 标头字段决定。 将位图图片传递为myimage.html
是完全合法的(但可能有点愚蠢),反之,将 HTML 页面传递为index.png
是完全合法的(但可能有点愚蠢)。 这也是为什么有人认为文件扩展名根本不应该成为 URI 的一部分的原因。Tim Berners-Lee 爵士在超文本样式:酷 URI 不会改变中详细阐述了这一点。
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 not encoded in its name. Instead, it is decided by the
Content-Type
HTTP header field. It's completely legitimate (but perhaps a bit stupid) to deliver a bitmap picture asmyimage.html
and conversely, to deliver an HTML page asindex.png
. This is also the reason why it is argued that file extensions shouldn't be part of URIs at all.Sir Tim Berners-Lee elaborates on this in Hypertext Style: Cool URIs Don't Change.
就我个人而言,我更喜欢 .html,但正如其他人所说,两者都可以。
只要确保只使用一个即可。 切勿两者都在同一个网站上!
mypage.html 的链接与 mypage.htm 的链接不同
Personally I prefer the .html but as other have said both will work.
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
我使用.htm。 我猜打字少了。 或者也许这是我的 Windows 偏见。
I use .htm. Less typing I guess. Or perhaps it's my windows-bias.
两者的工作方式相同,但有关技术和非技术参考,请在此处查找,
http://www.sightspecic.com/~mosh/www_faq/ext.html
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
在过去,两者都是正确的,文件扩展名的长度不得超过 3 个字符。
http://en.wikipedia.org/wiki/Filename_extension
Both are correct back in the past file extensions had to be a maximum of 3 characters long.
http://en.wikipedia.org/wiki/Filename_extension
我个人更喜欢 .html,因为它的名字是“超文本标记语言”。 使用 .htm 是因为某些旧版本的 Windows 文件扩展名不能超过 3 个字符
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,但当 Windows 95 出现时,它只能处理 3 个字符的扩展名。
因此,根据某些标准或其他标准,.html 是正确的,但实际上并不重要(大多数时候......刚刚进行了快速谷歌搜索并发现了以下内容)
不过,有一个值得关注的领域,大多数主机服务器将要求您的默认起始页命名为“index.html”而不是“index.htm”
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.
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)
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"