This site is supported by donations to The OEIS Foundation.
Template:URL/doc
From OeisWiki
The {{URL}} OEIS Wiki utility template is used either to encode an unencoded URL, or to extract sections from a URL.
Contents
- 1 URL
- 2 Usage
- 3 Examples
- 3.1 Examples of URL encoding
- 3.2 Examples with invalid input
- 3.3 Examples of URL sections extraction
- 3.3.1 Examples of protocol extraction
- 3.3.2 Examples of server.domain extraction
- 3.3.3 Examples of server extraction
- 3.3.4 Examples of domain extraction
- 3.3.5 Examples of port extraction
- 3.3.6 Examples of path extraction
- 3.3.7 Examples of query string extraction
- 3.3.8 Examples of fragment ID extraction
- 4 See also
- 5 Code
- 6 Notes
URL
An generic URL takes the form:[1]
- scheme:scheme-specific-part
Common Internet scheme syntax:
- //user:password@host:port/path
An HTTP URL takes the form:
- scheme://server.domain:port/path?query_string#fragment_id[2]
Every URL consists of some of the following:
- the scheme name (commonly called protocol), followed by a colon (:),
- two slashes (//), then, depending on scheme,
- for http protocol, either
- a server name (e.g. ftp, www, smtp, ...) followed by a dot (.) then a domain name, or
- a server IP address followed by a dot (.) then a domain IP address,
- optionally: a colon (:) followed by a port number,
- the path of the resource to be fetched or the program to be run, then,
- for programs such as Common Gateway Interface (CGI) scripts, a question mark (?) followed by a query string, and
- optionally: a hash sign (#) followed by a fragment identifier.
Usage
To get an encoded URL from an unencoded URL, use
- {{URL|unencoded URL}}
To extract a section from a URL, use
- {{URL|unencoded URL|URL section}}
where URL section is one of
- protocol or scheme
- server.domain
- server
- domain
- port
- path
- query string
- fragment id
Examples
Examples of URL encoding
Using
then
yields
- http%3A%2F%2Fen.wikipedia.org%2Fwiki%2FUniform_resource_locator%23Absolute_and_relative_URLs
Examples with invalid input
- {{URL|}}
yields
- URL error: First parameter (the unencoded URL) must be nonempty.
Using
- http%3A%2F%2Fen.wikipedia.org%2Fwiki%2FUniform_resource_locator%23Absolute_and_relative_URLs
then
- {{URL|http%3A%2F%2Fen.wikipedia.org%2Fwiki%2FUniform_resource_locator%23Absolute_and_relative_URLs}}
yields
- URL error: First parameter must be an unencoded URL (you may URL encode only once).
Examples of URL sections extraction
Examples of protocol extraction
yields
- http
yields
- http
Examples of server.domain extraction
- {{URL|http://en.wikipedia.org/wiki/Uniform_resource_locator#Absolute_and_relative_URLs|server.domain}}
yields
- en.wikipedia.org
- {{URL|http://en.wikipedia.org:80/wiki/Uniform_resource_locator#Absolute_and_relative_URLs|server.domain}}
yields
- en.wikipedia.org
Examples of server extraction
yields
- en
yields
- en
Examples of domain extraction
yields
- wikipedia.org
yields
- wikipedia.org
Examples of port extraction
yields
yields
Examples of path extraction
yields
- %2F%2Fen.wikipedia.org%2Fwiki%2FUniform_resource_locator
yields
- %2F%2Fen.wikipedia.org%3A80%2Fwiki%2FUniform_resource_locator
Examples of query string extraction
- {{URL|http://en.wikipedia.org/wiki/Uniform_resource_locator#Absolute_and_relative_URLs|query string}}
yields
- {{URL|http://en.wikipedia.org:80/wiki/Uniform_resource_locator#Absolute_and_relative_URLs|query string}}
yields
Examples of fragment ID extraction
- {{URL|http://en.wikipedia.org/wiki/Uniform_resource_locator#Absolute_and_relative_URLs|fragment ID}}
yields
- Absolute_and_relative_URLs
- {{URL|http://en.wikipedia.org:80/wiki/Uniform_resource_locator#Absolute_and_relative_URLs|fragment ID}}
yields
- Absolute_and_relative_URLs
See also
Code
Code for {{~URL}}
Notes
- ↑ T. Berners-Lee, L. Masinter, M. McCahill, Uniform Resource Locators (URL).
- ↑ Uniform resource locator—Wikipedia.org.