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}} OEIS Wiki utility template is used either to encode an unencoded URL, or to extract sections from a URL.

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

http://en.wikipedia.org/wiki/Uniform_resource_locator#Absolute_and_relative_URLs

then

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

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

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

yields

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

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

{{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

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

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

Examples of path extraction

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

yields

%2F%2Fen.wikipedia.org%2Fwiki%2FUniform_resource_locator
{{URL|http://en.wikipedia.org:80/wiki/Uniform_resource_locator#Absolute_and_relative_URLs|path}}

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

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