为什么有些站点 url 不包含文件扩展名? [英] How come some site urls do not include a file extension?

查看:36
本文介绍了为什么有些站点 url 不包含文件扩展名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在浏览互联网时注意到,例如,YouTube 包含一个表示视频页面的 URL:http://www.youtube.com/watch?v=gwS1tGLB0vc.

I was browsing the internet and noticed, YouTube, for example, contains a URL like this to denote a video page: http://www.youtube.com/watch?v=gwS1tGLB0vc.

我的网站使用这样的 URL 作为主题页面:http://www.example.com/page.php?topic_id=6f3246d0sdf42c2jb67abba60ce33d5cc.

My site uses a URL like this for a topic page: http://www.example.com/page.php?topic_id=6f3246d0sdf42c2jb67abba60ce33d5cc.

不同之处在于,如果您还没有注意到在 youtube 上,他们的观看页面没有文件扩展名,所以我想知道,为什么有些网站不使用文件扩展名,它有什么用途?

The difference is, if you haven't already noticed that on youtube, there is no file extension for their watch page, so I am wondering, why do some sites not use file extensions and what use does it serve?

推荐答案

不使用文件扩展名,因为 URI(以及 URL)应该独立于实现 - 如果您想访问 CDC 有关食品安全的信息,您应该可以访问 https://www.cdc.gov/foodsafety(例如).CDC 的服务器是使用 PHP、Python 还是 Perl 对最终用户来说并不重要,因此他们不应该看到它.最终用户并不关心页面是如何生成的,因为为网页提供服务的所有语言都输出相同的 HTML、CSS 等,而用户只是在他们的网络浏览器中查看页面.

File extensions are not used because of the idea that URIs (and therefore URLs) should be independent of implementation - if you want to access the CDC's information about food safety, you should be able to go to https://www.cdc.gov/foodsafety (for example). Whether the CDC's servers are using PHP or Python or Perl doesn't matter to the end-user, so they shouldn't see it. The end-user doesn't care how the page was generated, because all languages serving a webpage output the same HTML, CSS, and the like, and the user is just viewing the page in their web browser.

大多数网络框架都默认构建此功能,正是出于这个原因,并且无论在大多数网络服务器中重写 URL 都可以实现.这个理想被编纂在 W3C 风格指南中,这无疑是这个想法被广泛接受的重要支持者.在他们的指南中概述了,Cool URIs Don't Change",如果您仍然不太明白这里的推理,这应该会澄清事情.该文档是有关该问题的首选声明,也是框架的事实上的标准.

Most web frameworks build this functionality in by default, precisely for this reason, and it can be accomplished regardless with URL rewriting in most webservers. This ideal is codified in the W3C Style Guide, which is undoubtedly a big proponent in this idea being so widely accepted. It's outlined in their guide, "Cool URIs Don't Change", which should clear things up if you still don't quite understand the reasoning here. That document is the go-to statement on the issue, and the de facto standard for frameworks.

值得注意的是,通常最终被下载的文件(有时在 AJAX 中使用的数据文件)的文件扩展名仍然完好无损 - http://example.com/song.mp3http://example.com/whitepaper.pdf - 因为它们旨在保存到最终用户的计算机上,文件扩展名很重要.仅显示的页面不包含扩展程序 - 这是大多数页面.

It is worth noting that usually files that end up being downloaded (and sometimes data files used in AJAX) will still have their file extensions intact - http://example.com/song.mp3 or http://example.com/whitepaper.pdf - because they are intended to be saved to the end-user's computer, where file extensions matter. The extensions are not included for pages that are simply displayed - which is most pages.

附言:这个答案最初链接到的示例页面在某些时候停止存在,因为尽管有最佳实践,有时 URI 确实会发生变化.我已将其替换为 CDC 的食品安全页面,该页面以某种形式存在于 至少 20 年了.毫无疑问,多年来,许多不同的技术提供了这些内容,而且总是在完全相同的 URL 上提供.

A postscript: The example page this answer originally linked to stopped existing at some point, because sometimes URIs do change, despite best practices. I've replaced it with the CDC's food safety page, which has existed in some form for at least 20 years now. Undoubtedly, numerous different technologies have served up that content over the years, while always doing so at the exact same URL.

这篇关于为什么有些站点 url 不包含文件扩展名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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