问题
I am writing some documentation and I have a little vocabulary problem:
http://www.example.com/en/public/img/logo.gif
is called an \"absolute\" url, right?../../public/img/logo.gif
is called a \"relative\" url, right?- 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?
回答1:
Here are the URL components:
http://www.example.com/en/public/img/logo.gif
\__/ \_____________/\_____________________/
#1 #2 #3
- scheme/protocol
- host
- 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.
回答2:
It is sometimes called a virtual url, for example in SSI:
<!--#include virtual = "/lib/functions.js" -->
回答3:
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.
回答4:
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
回答5:
I have seen it called a root relative URL.
回答6:
Facebook would call /en/public/img/logo.gif
a protocol-relative URL (see their batch API).
来源:https://stackoverflow.com/questions/904046/absolute-urls-relative-urls-and