绝对 url、相对 url,以及...?

发布于 2024-07-22 14:55:12 字数 416 浏览 9 评论 0原文

我正在编写一些文档,但遇到了一些词汇问题:

  1. http://www.example.com/en/public/img/logo.gif 被称为“绝对”url,对吗?
  2. ../../public/img/logo.gif 被称为“相对”url,对吗?
  3. 那么如何称呼它:/en/public/img/logo.gif

尽管没有协议和域部分,它是否也被视为“绝对 URL”?

或者它是否被视为相对 URL,但相对于域的根?

我用谷歌搜索了一下,有些人将其归类为绝对,而另一些人则将其归类为相对。

我应该怎么称呼它? “半绝对网址”? 还是“半亲戚”? 还有一个词吗?

I am writing some documentation and I have a little vocabulary problem:

  1. http://www.example.com/en/public/img/logo.gif is called an "absolute" url, right?
  2. ../../public/img/logo.gif is called a "relative" url, right?
  3. so how do you call this: /en/public/img/logo.gif ?

Is it also considered an "absolute url", although without the protocol and domain parts?

Or is it considered a relative url, but relative to the root of the domain?

I googled a bit and some people categorize this as absolute, and others as relative.

What should I call it? A "semi-absolute url"? Or "semi-relative"? Is there another word?

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

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

发布评论

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

评论(6

明媚殇 2024-07-29 14:55:14

是的,相对 URL 有两种类型:具有相对路径的相对 URL 和具有绝对路径的相对 URL。

(1) 相对URL 相对路径=相对于当前页面的URL。 需要链接的文件或资源位于同一网站内。

例如,您正在访问 https://example.com/items/menu.html

您想要链接到与当前页面同一目录下的 images 文件夹中的图像文件,您可以使用相对 URL src="images/myimage.jpg"

生成的网址将为:https://example.com/items/images/myimage.jpg。 这是因为,当您不在 src="images/myimage.jpg" 中的 images 之前放置 / 时,您就是在告诉浏览器images 文件夹与 menu.html 文件位于同一目录中。

想象一下,在 example.com 文件夹内,有 items 文件夹,在 items 文件夹内有 images 文件夹和 >menu.html 文件。

因此它将从 https://example.com/items/menu.html 更改为 https://example.com/items/images/myimage.jpg 因为 <当您不在 images 之前放置 / 时,code>images 文件夹和 menu.html 位于同一级别。 就是这样!

(2) 相对URL,绝对路径=URL,指定从网站根目录开始的完整路径。

例如,您再次访问 https://example.com/items/menu.html

您在网站的根目录中有一个 images 文件夹。 P/s:根目录是https://example.com/

您想要链接到根文件夹中的图像文件,您可以使用绝对路径 src="/images/myimage.jpg" 的相对 URL。 请注意,在 images 之前有 / 来指定它将相对于根目录。

生成的网址将为:https://example.com/images/myimage.jpg。 它将从 https://example.com/items/menu.html 更改为 https://example.com/images/myimage.jpg 因为 images 文件夹位于根目录中。 就是这样!

(3) 长话短说,

您正在访问 https://example.com/items/menu.html

如果您使用src="images/myimage.jpg"
生成的 URL 将为 https://example.com/items/images/myimage.jpg

如果您使用src="/images/myimage.jpg"
生成的 URL 将为 https://example.com/images/myimage.jpg

Yes, there are two types of relative URLs: relative URLs with a relative path and relative URLs with an absolute path.

(1) Relative URL with relative path = relative to the current page's URL. Files or resources that need to be linked are located within the same website.

Example, you are on https://example.com/items/menu.html.

You want to link to an image file in the images folder in the same directory as the current page, you would use the relative URL src="images/myimage.jpg".

The resulting url will be: https://example.com/items/images/myimage.jpg. This is because, when you don't put / before images in src="images/myimage.jpg", you are telling the browser that the images folder is located in the same directory as the menu.html file.

Imagine, inside example.com folder, has items folder, inside items folder has both images folder and menu.html file.

So it will change from https://example.com/items/menu.html to https://example.com/items/images/myimage.jpg because images folder and menu.html are on the same level when you don't put / before images. That's it!

(2) Relative URLs with absolute path = URL that specify the complete path starting from the root directory of the website.

Example, you are on https://example.com/items/menu.html again.

You have an images folder at the root directory of the website. P/s: Root directory is https://example.com/.

You want to link to an image file in root folder, you would use the relative URL with absolute path src="/images/myimage.jpg". Notice that it has / before images to specify that it will be relative to root directory.

The resulting url will be: https://example.com/images/myimage.jpg. It will change from https://example.com/items/menu.html to https://example.com/images/myimage.jpg because images folder are on the root directory. That's it!

(3) Long story short,

You are on https://example.com/items/menu.html.

If you use src="images/myimage.jpg",
resulting URL will be https://example.com/items/images/myimage.jpg.

If you use src="/images/myimage.jpg",
resulting URL will be https://example.com/images/myimage.jpg.

水溶 2024-07-29 14:55:13

请记住可以省略 URL 的多少段,使它们成为相对的(注意:全部都是)。 这些都是有效的 URL:

  • http://example.com/bar?baz
  • ?qoo=qalue
  • /bar2
  • dat/sly
  • //auth.example.com (大多数人都对这个感到惊讶!将使用 http 或 https,具体取决于当前资源)
  • #anchor

Keep in mind just how many segments of the URL can be omited, making them relative (note: its all of them, just about). These are all valid URLs:

  • http://example.com/bar?baz
  • ?qoo=qalue
  • /bar2
  • dat/sly
  • //auth.example.com (most people are surprised by this one! Will use http or https, depending on the current resource)
  • #anchor
顾挽 2024-07-29 14:55:13

它有时被称为虚拟 url,例如在 SSI 中:

<!--#include virtual = "/lib/functions.js" -->

It is sometimes called a virtual url, for example in SSI:

<!--#include virtual = "/lib/functions.js" -->
情何以堪。 2024-07-29 14:55:13

来自 Microsoft 的有关 绝对和相对网址

URL 指定存储在本地或网络计算机上的目标的位置。 目标可以是文件、目录、HTML 页面、图像、程序等。

绝对 URL 包含定位资源所需的所有信息。

相对 URL 使用绝对 URL 作为起点来定位资源。 实际上,目标的“完整 URL”是通过连接绝对 URL 和相对 URL 来指定的。

绝对 URL 使用以下格式:scheme://server/path/resource

相对 URL 通常仅包含路径,以及可选的资源,但不包含方案服务器。 下表定义了完整 URL 格式的各个部分。

  • 方案 - 指定如何访问资源

  • 服务器 - 指定资源所在的计算机的名称。

  • 路径 - 指定通向目标的目录顺序。 如果省略资源,则目标是路径中的最后一个目录。

  • 资源 - 如果包含,资源是目标,通常是文件的名称。 它可能是一个包含单个二进制字节流的简单文件,也可能是一个结构化文档,包含一个或多个存储和二进制字节流。

    < /里>

From the Microsoft's documentation about Absolute and Relative URLs

A URL specifies the location of a target stored on a local or networked computer. The target can be a file, directory, HTML page, image, program, and so on.

An absolute URL contains all the information necessary to locate a resource.

A relative URL locates a resource using an absolute URL as a starting point. In effect, the "complete URL" of the target is specified by concatenating the absolute and relative URLs.

An absolute URL uses the following format: scheme://server/path/resource

A relative URL typically consists only of the path, and optionally, the resource, but no scheme or server. The following tables define the individual parts of the complete URL format.

  • scheme - Specifies how the resource is to be accessed.

  • server - Specifies the name of the computer where the resource is located.

  • path - Specifies the sequence of directories leading to the target. If resource is omitted, the target is the last directory in path.

  • resource - If included, resource is the target, and is typically the name of a file. It may be a simple file, containing a single binary stream of bytes, or a structured document, containing one or more storages and binary streams of bytes.

遮了一弯 2024-07-29 14:55:12

以下是 URL 组成部分:

http://www.example.com/en/public/img/logo.gif
\__/   \_____________/\_____________________/
 #1     #2             #3
  1. 方案/协议
  2. 主机
  3. 路径

如果 URL 以方案和方案特定部分开头(此处 //< /code> 在 http: 之后)。 其他都是相对 URL

如果URL 路径/ 开头,则称为绝对URL 路径。 任何其他URL 路径都称为相对URL 路径

因此:

  • http://www.example.com/en/public/img/logo.gif 是一个绝对 URL
  • ../../public /img/logo.gif 是一个相对 URL,带有相对 URL 路径
  • /en/public/img/logo.gif 是一个带有绝对 URL 路径相对 URL

注意:URI 的当前定义 (RFC 3986) 与旧的 URL 定义不同 (RFC 1738 和 RFC 1808)。

带有 URI 术语的三个示例:

  • http://www.example.com/en/public/img/logo.gif 是一个URI
  • ../../public/img/ logo.gif 是一个相对引用,只有一个相对路径,而
  • /en/public/img/logo.gif 是一个仅带有绝对路径相对引用

Here are the URL components:

http://www.example.com/en/public/img/logo.gif
\__/   \_____________/\_____________________/
 #1     #2             #3
  1. scheme/protocol
  2. host
  3. path

A URL is called an absolute URL if it begins with the scheme and scheme specific part (here // after http:). Anything else is a relative URL.

A URL path is called an absolute URL path if it begins with a /. Any other URL path is called a relative URL path.

Thus:

  • http://www.example.com/en/public/img/logo.gif is a absolute URL,
  • ../../public/img/logo.gif is a relative URL with a relative URL path and
  • /en/public/img/logo.gif is a relative URL with an absolute URL path.

Note: The current definition of URI (RFC 3986) is different from the old URL definition (RFC 1738 and RFC 1808).

The three examples with URI terms:

  • http://www.example.com/en/public/img/logo.gif is a URI,
  • ../../public/img/logo.gif is a relative reference with just a relative path and
  • /en/public/img/logo.gif is a relative reference with just an absolute path.
流云如水 2024-07-29 14:55:12

我看到它被称为根相对 URL

I have seen it called a root relative URL.

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