This site is supported by donations to The OEIS Foundation.

Template:~URL/doc

From OeisWiki
Jump to: navigation, search

This documentation subpage contains instructions, categories, or other information for Template:~URL. [<Edit> Template:~URL]

[⧼Purge⧽ Template:~URL/doc]

alt = This template is under construction...
This template is under construction.            

Please do not use this unfinished and/or still unreliable template.            


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.

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

{{~URL|http://en.wikipedia.org/wiki/Uniform_resource_locator#Absolute_and_relative_URLs|protocol}}

yields

http 
{{~URL|http://en.wikipedia.org:80/wiki/Uniform_resource_locator#Absolute_and_relative_URLs|scheme}}

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

{{~URL|http://en.wikipedia.org/wiki/Uniform_resource_locator#Absolute_and_relative_URLs|host}}

yields

en.wikipedia.org 
{{~URL|http://en.wikipedia.org:80/wiki/Uniform_resource_locator#Absolute_and_relative_URLs|server.domain}}

yields

en.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|host}}

yields

www.google.ca 

Examples of server extraction

{{~URL|http://en.wikipedia.org/wiki/Uniform_resource_locator#Absolute_and_relative_URLs|server}}

yields

en 
{{~URL|http://en.wikipedia.org:80/wiki/Uniform_resource_locator#Absolute_and_relative_URLs|server}}

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

{{~URL|http://en.wikipedia.org/wiki/Uniform_resource_locator#Absolute_and_relative_URLs|domain}}

yields

wikipedia.org 
{{~URL|http://en.wikipedia.org:80/wiki/Uniform_resource_locator#Absolute_and_relative_URLs|domain}}

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

{{~URL|http://en.wikipedia.org/wiki/Uniform_resource_locator#Absolute_and_relative_URLs|port}}

yields

 
{{~URL|http://en.wikipedia.org:80/wiki/Uniform_resource_locator#Absolute_and_relative_URLs|port}}

yields

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|port}}

yields

 

Examples of path or CGI script extraction

{{~URL|http://en.wikipedia.org/wiki/Uniform_resource_locator#Absolute_and_relative_URLs|path}}

yields

wiki/Uniform_resource_locator 
{{~URL|http://en.wikipedia.org:80/wiki/Uniform_resource_locator#Absolute_and_relative_URLs|path}}

yields

wiki/Uniform_resource_locator 
{{~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|path}}

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

  1. T. Berners-Lee, L. Masinter, M. McCahill, Uniform Resource Locators (URL).