This site is supported by donations to The OEIS Foundation.
Template:~URL
From OeisWiki
The following documentation is located at Template:~URL/doc. [<Edit> Template:~URL/doc]
[⧼Purge⧽ Template:~URL]
[⧼Purge⧽ Template:~URL]
The {{~URL}} helper function template (whose purpose is to extract components from a HTTP/HTTPS URL) is used by the {{URL}} OEIS Wiki utility template.
Contents
- 1 URL
- 2 Usage
- 3 Examples
- 3.1 Examples with invalid input
- 3.2 Examples with valid input
- 3.2.1 Examples of scheme extraction
- 3.2.2 Examples of scheme-specific-part extraction
- 3.2.3 Examples of host:port extraction
- 3.2.4 Examples of host extraction
- 3.2.5 Examples of server extraction
- 3.2.6 Examples of domain extraction
- 3.2.7 Examples of port extraction
- 3.2.8 Examples of path or CGI script extraction
- 3.2.9 Examples of query string extraction
- 3.2.10 Examples of fragment ID extraction
- 4 Code
- 5 See also
- 6 Notes
URL
A generic URL takes the form[1]
- scheme:scheme-specific-part
The common internet scheme-specific-part syntax is
- //user:password@host:port/path
A HTTP/HTTPS URL takes the form
- scheme://server.domain:port/path?query_string#fragment_id
where
- the scheme (commonly called protocol) name (http or https), followed by a colon (:),
- two slashes (//), then either
- a server name (e.g. www, ...) followed by a dot (.) then a domain, or
- a server IP address followed by a dot (.) then a domain IP address,
- optionally: a colon (:) followed by a port number (default 80 for http, 443 for https), then
- 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 query string (search part), and
- optionally: a hash sign (#) followed by a fragment ID (anchor ID).
Usage
To extract a component from a URL, use
- {{~URL|unencoded URL|URL component}}
where URL component is one of
- protocol or scheme
- scheme-specific-part
- host or server.domain
- server
- domain
- port
- path
- query string or search part
- fragment ID or anchor ID
Examples
Examples with invalid input
- {{~URL|}}
yields
- ~URL error: First parameter (the unencoded URL) must be nonempty.
- {{~URL|http%3A%2F%2Fen.wikipedia.org%2Fwiki%2FUniform_resource_locator%23Absolute_and_relative_URLs}}
yields
- ~URL error: First parameter (the unencoded URL) must be unencoded.
Examples with valid input
Examples of scheme extraction
yields
- http
yields
- http
- {{~URL|https://www.google.ca/search?q=Fibonacci+polynomials+triangle&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a|scheme}}
yields
- https
Examples of scheme-specific-part extraction
- {{~URL|http://en.wikipedia.org/wiki/Uniform_resource_locator#Absolute_and_relative_URLs|scheme specific part}}
yields
- en.wikipedia.org/wiki/Uniform_resource_locator#Absolute_and_relative_URLs
- {{~URL|http://en.wikipedia.org:80/wiki/Uniform_resource_locator#Absolute_and_relative_URLs|scheme specific part}}
yields
- en.wikipedia.org:80/wiki/Uniform_resource_locator#Absolute_and_relative_URLs
- {{~URL|https://www.google.ca/search?q=Fibonacci+polynomials+triangle&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a|scheme-specific-part}}
yields
- www.google.ca/search?q=Fibonacci+polynomials+triangle&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a
Examples of host:port extraction
- {{~URL|http://en.wikipedia.org/wiki/Uniform_resource_locator#Absolute_and_relative_URLs|server.domain:port}}
yields
- en.wikipedia.org
- {{~URL|http://en.wikipedia.org:80/wiki/Uniform_resource_locator#Absolute_and_relative_URLs|host:port}}
yields
- en.wikipedia.org:80
- {{~URL|https://www.google.ca/search?q=Fibonacci+polynomials+triangle&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a|host:port}}
yields
- www.google.ca
Examples of host extraction
yields
- en.wikipedia.org
- {{~URL|http://en.wikipedia.org:80/wiki/Uniform_resource_locator#Absolute_and_relative_URLs|server.domain}}
yields
- en.wikipedia.org
yields
- www.google.ca
Examples of server extraction
yields
- en
yields
- en
- {{~URL|https://www.google.ca/search?q=Fibonacci+polynomials+triangle&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a|server}}
yields
- www
Examples of domain extraction
yields
- wikipedia.org
yields
- wikipedia.org
- {{~URL|https://www.google.ca/search?q=Fibonacci+polynomials+triangle&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a|domain}}
yields
- google.ca
Examples of port extraction
yields
yields
- 80
yields
Examples of path or CGI script extraction
yields
- wiki/Uniform_resource_locator
yields
- wiki/Uniform_resource_locator
yields
- search
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
- {{~URL|https://www.google.ca/search?q=Fibonacci+polynomials+triangle&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a|query string}}
yields
- q=Fibonacci+polynomials+triangle&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a
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
- {{~URL|https://www.google.ca/search?q=Fibonacci+polynomials+triangle&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a|fragment ID}}
yields
Code
See also
Notes
- ↑ T. Berners-Lee, L. Masinter, M. McCahill, Uniform Resource Locators (URL).