url定位符_什么是URL(统一资源定位符)?

url定位符

url定位符

When you type an address into your web browser, a lot of things happen behind the scenes. And most of that is determined by the various parts of the URL you typed. Let’s take a closer look.

当您在网络浏览器中键入地址时,幕后发生了很多事情。 而大多数情况取决于您输入的URL的各个部分。 让我们仔细看看。

A URL can consist of a bunch of different parts. There’s a hostname that maps to an IP address of a specific resource on the internet and bunch of additional information that tells your browser and the server how to handle things. You can think of an IP address as being something like a phone number. A hostname is like the name of a person whose phone number you want to look up. And a standard called the Domain Name System (DNS) works in the background like a phone book, translating the more human-friendly hostnames into the IP addresses that networks use to route traffic.

URL可以由许多不同的部分组成。 有一个主机名映射到Internet上特定资源的IP地址,还有一堆附加信息,这些信息告诉您的浏览器和服务器如何处理事情。 您可以将IP地址视为电话号码之类的东西。 主机名就像您要查找其电话号码的人的名字。 还有一个称为域名系统(DNS)的标准在后台像电话簿一样工作,它将对人类更友好的主机名转换为网络用来路由流量的IP地址。

Keeping that analogy in mind, let’s take a look at the structure of a URL and how it works to get you where you want to go.

牢记这一类比,让我们看一下URL的结构及其如何使您到达想要的位置。

URL的结构 (How a URL Is Structured)

The structure of a URL was first defined by Sir Tim Berners-Lee—the guy who created the Web and the first web browser—in 1994. URLs essentially combine the idea of domain names with the idea of using a file path to identify a specific folder and file structure. So, it’s similar to using a path like C:\Documents\Personal\myfile.txt in Windows, but with some extra stuff at the beginning to help find the right server on the internet where that path exists and the protocol used to access the information.

URL的结构最早由Tim Berners-Lee爵士(创建Web和第一个Web浏览器的人)于1994年定义。URL本质上将域名的思想与使用文件路径标识特定内容的思想结合在一起。文件夹和文件结构。 因此,这类似于在Windows中使用诸如C:\ Documents \ Personal \ myfile.txt之类的路径,但是在开始时会有一些额外的东西,以帮助在互联网上找到该路径所在的正确服务器以及用于访问该服务器的协议。信息。

A URL consists of several different parts. Take, for example, a basic URL like the one shown in the image below.

URL由几个不同部分组成。 以一个基本URL为例,如下图所示。

That simple URL is broken down into two major components: the scheme and the authority.

这个简单的URL分为两个主要部分:方案和授权。

方案 (Scheme)

A lot of people think of a URL as just a web address, but it’s not quite that simple. A web address is a URL, but all URLs are not web addresses. Other services you can access on the internet—like FTP—or even locally—like MAILTO—are also URLs. The scheme portion of a URL (those letters followed by a colon) denote the protocol with which an app (like your web browser) and the server should communicate.

许多人认为URL只是一个网址,但并不是那么简单。 网址是一个URL,但是所有URL都不是网址。 您可以在Internet上访问的其他服务(例如FTP)或什至在本地(例如MAILTO)也是URL。 URL的方案部分(那些字母后跟冒号)表示应用程序(例如Web浏览器)与服务器之间应使用的协议。

Web addresses are the most common URL, but there are others. So, you might see schemes like:

网址是最常见的URL,但还有其他URL。 因此,您可能会看到类似以下的方案:

  • HyperText Transfer Protocol (HTTP): This is the underlying protocol of the web and determines what actions web servers and browsers should take in response to certain commands.

    超文本传输​​协议(HTTP):这是Web的基础协议,它确定Web服务器和浏览器应响应某些命令而采取的操作。
  • HTTP Secure (HTTPS): This is a form of HTTP that works over a secure, encrypted layer for safer transport of information.

    HTTP安全( HTTPS ) :这是HTTP的一种形式,它在安全的加密层上工作,以更安全地传输信息。

  • File Transfer Protocol (FTP): This protocol is often still used for transferring files over the internet.

    文件传输协议(FTP):该协议通常仍用于通过Internet传输文件。

In modern browsers, the scheme isn’t technically required as part of the URL. If you enter a website like “www.howtogeek.com”, your browser will automatically determine the right protocol to use. Still, some other apps (and protocols) require the use of a scheme.

在现代浏览器中,从技术上讲,该方案并不是URL的一部分。 如果您输入“ www.howtogeek.com”之类的网站,则浏览器将自动确定要使用的正确协议。 尽管如此,其他一些应用程序(和协议)仍需要使用方案。

权威 (Authority)

The authority portion of a URL (which is preceded by two slashes) is itself broken down into a bunch of parts. Let’s start off with a very simple URL—the kind that would take you to the home page of a website.

URL的授权部分(前面带有两个斜杠)本身被分解为许多部分。 让我们从一个非常简单的URL开始,这种URL会将您带到网站的主页。

In this simple example, the whole “www.example.com” part is called a hostname, and it resolves to an IP address. You can also type an IP address into your browser’s address bar instead of the hostname if you happen to know it.

在此简单示例中,整个“ www.example.com”部分称为主机名,它解析为IP地址。 如果您碰巧知道,也可以在浏览器的地址栏中输入IP地址而不是主机名。

But, when parsing the hostname it helps to read it backward to understand what’s going on, so here are those components:

但是,在解析主机名时,它有助于向后读取它,以了解正在发生的事情,因此以下是这些组件:

  • Top-Level Domain: In the example here, “com” is the top-level domain. These are the highest level in the Domain Name System (DNS) hierarchy used to translate IP addresses into simple language addresses that are easier for we humans to remember. These top-level domains are created and managed by the Internet Corporation for Assigned Names and Numbers (ICANN). The three most common top-level domains are .com, .net, and .gov. Most countries also have their own two-letter top-level domain, so you’ll see domains like .us (United States), .uk (United Kingdom), .ca (Canada), and many others. There are also some additional top-level domains (like .museum) that are sponsored and managed by private organizations. In addition to these, there are also some generic top-level domains (like .club, .life, and .news).

    顶级域:在此处的示例中,“ com”是顶级域。 这些是域名系统 (DNS)层次结构中的最高级别,用于将IP地址转换为简单的语言地址,我们人类更容易记住这些地址。 这些顶级域是由互联网名称与数字地址分配机构(ICANN)创建和管理的。 三个最常见的顶级域是.com,.net和.gov。 大多数国家/地区都有自己的两个字母的顶级域名,因此您会看到.us(美国)、. uk(英国)、. ca(加拿大)等域名。 还有一些其他的顶级域名(例如.museum)由私有组织赞助和管理。 除这些以外,还有一些通用顶级域(例如.club,.life和.news)。

  • Subdomain: Since DNS is a hierarchical system, both the “www” and “example” parts of our example URL are considered subdomains. The “www” portion is a subdomain of the “com” top-level domain, and the “www” portion is a subdomain of the “example” domain. That’s why you’ll often see a company with a registered name like “google.com” broken out into separate subdomains like “www.google.com,” “news.google.com,” “mail.google.com,” and so on.

    子域:由于DNS是分层系统,因此示例URL的“ www”和“ example”部分均被视为子域。 “ www”部分是“ com”顶级域的子域,而“ www”部分是“ example”域的子域。 这就是为什么您经常会看到一家注册名称为“ google.com”的公司细分为“ www.google.com”,“ news.google.com”,“ mail.google.com”和“以此类推。

That’s the most basic example of the authority section of a URL, but things can get more complicated. There are two other components that the authority section can contain:

这是URL授权部分的最基本示例,但是事情可能变得更加复杂。 授权部分可以包含两个其他组件:

  • User Information: The authority section can also contain a username and password for the site you’re accessing. It’s uncommon to see this structure in URLs today, but it can happen. If present, the user info portion comes before the hostname and is followed by an @ sign. So, you might see something like “//username:password@www.example.com” if it includes the user information.

    用户信息:权限部分还可以包含您正在访问的站点的用户名和密码。 如今在URL中看到这种结构并不常见,但是这种情况可能发生。 如果存在,则用户信息部分位于主机名之前,后跟@符号。 因此,如果包含用户信息,您可能会看到类似“ //username:password@www.example.com”的内容。

  • Port Number: Network devices use IP addresses to get information to the right computer on a network. When that traffic arrives, a port number tells the computer the application for which that traffic is intended. The port number is another element you won’t often see when browsing the web, but you might see it in network apps (like games) that require you to enter a URL. If the URL includes a port number, it comes after the hostname and is preceded by a colon. It would look something like this: “//www.example.com:8080.”

    端口号:网络设备使用IP地址将信息获取到网络上正确的计算机。 当该流量到达时,端口号告诉计算机该流量所针对的应用程序。 端口号是浏览网络时很少看到的另一个元素,但是您可能会在需要输入URL的网络应用程序(例如游戏)中看到它。 如果URL包含端口号,则它在主机名之后,并以冒号开头。 看起来像这样:“ // www.example.com:8080”。

So, that’s the scheme and authority portions of a URL, but as you might have guessed after looking at a lot of URLs while browsing the web, they can include even more stuff.

因此,这就是URL的方案和权限部分,但是正如您在浏览Web时查看许多URL之后可能已经猜到的那样,它们可能包含更多内容。

路径,查询和片段 (Paths, Queries, and Fragments)

There are three additional parts of a URL that you might see after the authority portion: paths, queries, and fragments. Here’s how those work.

在权限部分之后,您可能会看到URL的三个附加部分:路径,查询和片段。 这些是这样的。

路径 (Path)

The authority section of a URL gets your browser (or whatever app) to the right server on a network. The path that follows—which works just like a path in Windows, macOS, or Linux—gets you to the right folder or file on that server. The path is preceded by a slash, and there’s a slash between every directory and subdirectory, like this:

URL的权限部分会将您的浏览器(或任何应用程序)连接到网络上的正确服务器。 遵循的路径(与Windows,macOS或Linux中的路径一样工作)使您进入该服务器上的正确文件夹或文件。 路径前面有一个斜杠,每个目录和子目录之间都有一个斜杠,如下所示:

www.example.com/folder/subfolder/filename.html

The last piece is the name of the file that is opened when you access the website. Although you may not see it in the address bar, that doesn’t mean it isn’t there. Some languages used to create web pages hide the file name and extension you’re viewing. This makes the URL easier to remember and type, and gives it a cleaner look.

最后一部分是您访问网站时打开的文件的名称。 尽管您可能在地址栏中看不到它,但这并不意味着它不存在。 用于创建网页的某些语言会隐藏您正在查看的文件名和扩展名。 这使URL易于记住和键入,并使其外观更简洁。

询问 (Query)

The query portion of a URL is used to identify things that aren’t part of a strict path structure. Most often, you’ll see them used when you perform a search or when a web page delivers data through a form. The query portion is preceded by a question mark and comes after the path (or after the hostname if a path is not included).

URL的查询部分用于识别不属于严格路径结构的内容。 通常,您会在执行搜索或网页通过表单传递数据时看到它们的使用。 查询部分的前面是问号,并且位于路径之后(如果不包括路径,则位于主机名之后)。

As an example, take this URL presented when we searched Amazon for the keywords “wi-fi extender”:

例如,以当我们在亚马逊上搜索关键字“ wi-fi扩展器”时显示的URL:

https://www.amazon.com/s/ref=nb_sb_noss_2?url=search-alias%3Daps&field-keywords=wi-fi+extender

The search form passed information to Amazon’s search engine. Following the question mark, you can see there are two parts to the query: a URL for the search (that’s the “url=search-alias%3Daps&field” part) and the keywords we typed (that’s the “keywords=wi-fi+extender” part).

搜索表单将信息传递给了亚马逊的搜索引擎。 在问号之后,您可以看到查询有两个部分:搜索的URL(即“ url = search-alias%3Daps&field”部分)和我们键入的关键字(即“ keywords = wi-fi +扩展程序”部分)。

That’s a fairly simple example, and you’ll often see URLs with additional (and more complicated) variables. For example, here’s the URL when we searched Google for the keyword “howtogeek”:

那是一个非常简单的示例,并且您经常会看到带有其他(更复杂)变量的URL。 例如,这是当我们在Google中搜索关键字“ howtogeek”时的网址:

https://www.google.com/search?q=howtogeek&rlz=1C1GCEA_enUS751US751&oq=howtogeek&aqs=chrome..69i57j69i60l4j0.1839j1j4&sourceid=chrome&ie=UTF-8

As you can see, there’s some different information there. In this case, you can see that there’s additional information indicating the search language, the browser we used (Chrome), and even the version number of the browser.

如您所见,那里有一些不同的信息。 在这种情况下,您可以看到还有其他信息,指示搜索语言,我们使用的浏览器(Chrome)以及浏览器的版本号。

分段 (Fragment)

The final component of a URL that you might see is called a fragment. The fragment is preceded by a hash mark (#) and is used to indicate a specific location on a web page. When coding a web page, designers can create anchors for specific text like headings. When the proper fragment is used at the end of a URL, your browser will load the page and then jump to that anchor. Anchors and URLs with fragments are often used to create tables of content on web pages to make navigation easier.

您可能会看到的URL的最终组成部分称为片段。 该片段前面带有一个井号(#),用于指示网页上的特定位置。 对网页进行编码时,设计人员可以为标题等特定文本创建锚点。 在URL末尾使用正确的片段时,浏览器将加载页面,然后跳转到该锚点。 带有片段的锚点和URL通常用于在网页上创建目录,以使导航更加容易。

Here’s an example. Wikipedia’s page on the Renaissance is quite a long document, and it’s broken up into about 11 sections, each of which has multiple subsections. But each heading on the page has an anchor included, and a table of contents at the top of the article includes links that let you jump to the different sections. Those links work by including fragments.

这是一个例子。 维基百科关于文艺复兴时期的页面是一个很长的文档,分为大约11个部分,每个部分都有多个小节。 但是页面上的每个标题都包含一个锚点,并且文章顶部的目录包含可让您跳至不同部分的链接。 这些链接通过包含片段来工作。

You can also use these fragments directly in your address bar or as shareable links. Say, for example, you wanted to show somebody the section of that page that covers Russia. You could just send them this link:

您也可以直接在地址栏中使用这些片段或将其用作共享链接。 举例来说,假设您想向某人展示该页面涵盖俄罗斯的部分。 您可以发送以下链接给他们:

https://en.wikipedia.org/wiki/Renaissance#Russia

That “#Russia” part at the end of the URL jumps them straight to that section after loading the page.

URL末尾的“ #Russia”部分将其在加载页面后直接跳转到该部分。



So there you have it—more than you likely ever wanted to know about how URLs work.

因此,有了它,您比以往任何时候都更想了解URL的工作原理。

Image Credit: Pawel Horazy/Shutterstock

图片来源: Pawel Horazy / Shutterstock

翻译自: https://www.howtogeek.com/356563/what-is-a-url-uniform-resource-locator/

url定位符

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值