Questions tagged [uri]

A Uniform Resource Identifier (or URI) is a string of characters used to identify a name or resource. URI is legacy terminology. In most cases, the term URL should be used instead.

A Uniform Resource Identifier (or URI) is a string of characters used to identify a name or resource.

Note: The current URL Standard at https://url.spec.whatwg.org/#url-representation supersedes RFC 3986 and dispenses with the use of the term URI, as documented in its Goals section:

Standardize on the term URL. URI and IRI are just confusing. In practice a single algorithm is used for both so keeping them distinct is not helping anyone. URL also easily wins the search result popularity contest.

But the information below documents URI in terms of the legacy RFC 3986 spec.


Structure

A URI can be a Uniform Resource Locator , a Uniform Resource Name , or both.

RFC 3986 defines a URI as composed of the following parts:

    foo://example.com:8042/over/there?name=ferret#nose
    \_/   \______________/\_________/ \_________/ \__/
     |           |            |            |        |
  scheme     authority       path        query   fragment

Then defining relative URIs (Section 5.2), you can omit any of those sections, always starting from the left. In pseudo-code, it looks like this:

 result = ""

  if defined(scheme) then
     append scheme to result;
     append ":" to result;
  endif;

  if defined(authority) then
     append "//" to result;
     append authority to result;
  endif;

  append path to result;

  if defined(query) then
     append "?" to result;
     append query to result;
  endif;

  if defined(fragment) then
     append "#" to result;
     append fragment to result;
  endif;

  return result;

The URI you are describing is a scheme-less relative URI.

Examples

For example, in the following URI:

https://stackoverflow.com/questions/tagged/uri?sort=newest&pagesize=50#questions

... the components are:

  • scheme: https

  • hierarchical part: //stackoverflow.com/questions/tagged/uri

  • query: sort=newest&pagesize=50

  • fragment: questions

The precise syntax of the individual components varies depending on the scheme. Here are some examples:

  • mailto:nobody@example.com?subject=Hello&body=Is%20anybody%20home%3F

  • data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=

  • urn:ietf:rfc:3986

URL

A URL is a URI but is more specific. In addition to identifying a web resource, a URL specifies the means of acting upon or obtaining the representation, specifying both its primary access mechanism and network location.

For example, the URL http://example.org/wiki/Main_Page refers to a resource identified as /wiki/Main_Page whose representation, in the form of HTML and related code, obtainable via HyperText Transfer Protocol (http) from a network host whose domain name is example.org.

URI Reference

A URI reference may take the form of a full URI, or just the scheme-specific portion of one, or even some trailing component thereof – even the empty string. An optional fragment identifier, preceded by #, may be present at the end of a URI reference. The part of the reference before the # indirectly identifies a resource, and the fragment identifier identifies some portion of that resource.

To derive a URI from a URI reference, software converts the URI reference to 'absolute' form by merging it with an absolute 'base' URI according to a fixed algorithm. The system treats the URI reference as relative to the base URI, although in the case of an absolute reference, the base has no relevance. The base URI typically identifies the document containing the URI reference, although this can be overridden by declarations made within the document or as part of an external data transmission protocol. If the base URI includes a fragment identifier, it is ignored during the merging process. If a fragment identifier is present in the URI reference, it is preserved during the merging process.

Web document markup languages frequently use URI references to point to other resources, such as external documents or specific portions of the same logical document.

Uses of URI references in markup languages

  • In HTML, the value of the src attribute of the img element provides a URI reference, as does the value of the href attribute of the a or link element.
  • In XML, the system identifier appearing after the SYSTEM keyword in a DTD is a fragmentless URI reference.
  • In XSLT, the value of the href attribute of the xsl:import element/instruction is a URI reference; likewise the first argument to the document() function.

Examples of absolute URIs

Examples of URI references

6139 questions
103
votes
4 answers

Are query string keys case sensitive?

Suppose I have a url like this: http://www.example.com?key=123&KEY=198 Then what will be result of request.querystring("key") and request.querystring("KEY") I am a bit confused.
100
votes
2 answers

Replace host in Uri

What is the nicest way of replacing the host-part of an Uri using .NET? I.e.: string ReplaceHost(string original, string newHostName); //... string s = ReplaceHost("http://oldhostname/index.html",…
Rasmus Faber
  • 48,631
  • 24
  • 141
  • 189
95
votes
4 answers

URI starting with two slashes ... how do they behave?

Lately I saw working code-blocks like this: And according to RFC 2396 (URI Syntax) and RFC 2616 (HTTP 1.1) these URI starting with two slashes…
pagid
  • 13,559
  • 11
  • 78
  • 104
94
votes
4 answers

How do you create a mailto: link without the (to) part

How do you properly construct a mailto: link without the part. mailto:someaddress@example.com? I dont want the address and just want whats in the parameters afterward to be filled in through the mailto.
Chamilyan
  • 9,347
  • 10
  • 38
  • 67
94
votes
8 answers

What do you call the entire first part of a URL?

If I have a URL like: http://www.example.com:9090/test.html Then I know that www.example.com is the host name, but what do you call http://www.example.com:9090? Is there some kind of established name for that?
jnicklas
  • 2,155
  • 2
  • 16
  • 14
93
votes
1 answer

When to use query parameters versus matrix parameters?

Query parameters: http://example.com/apples?order=random&color=blue Matrix parameters: http://example.com/apples;order=random;color=blue When should one use query parameters versus matrix parameters? Why can matrix parameters be used in the middle…
Gili
  • 86,244
  • 97
  • 390
  • 689
92
votes
17 answers

How to use "Share image using" sharing Intent to share images in android?

I have an image galley app; in that app I placed all the images into the drawable-hdpi folder. I call images in my activity like this: private Integer[] imageIDs = { R.drawable.wall1, R.drawable.wall2, R.drawable.wall3,…
Abhijeet
  • 1,057
  • 1
  • 8
  • 7
84
votes
21 answers

Easy way to parse a url in C++ cross platform?

I need to parse a URL to get the protocol, host, path, and query in an application I am writing in C++. The application is intended to be cross-platform. I'm surprised I can't find anything that does this in the boost or POCO libraries. Is it…
Andrew Bucknell
  • 1,880
  • 3
  • 21
  • 32
84
votes
5 answers

Get path and query string from URL using javascript

I have this: http://127.0.0.1:8000/found-locations/?state=--&km=km I want this: found-locations/?state=--&km=km how do i do this in javascript? I tried window.location.href but it is giving me whole url I tried…
doniyor
  • 36,596
  • 57
  • 175
  • 260
82
votes
12 answers

So what IS the right direction of the path's slash (/ or \) under Windows?

It seems Windows insists on writing a backslash \ in file paths, whereas .NET's URI class writes them with a slash /. Is there any right way, that is accepted even in the most primitive systems? And why is .NET's URI showing the other slash…
Letterman
  • 4,076
  • 5
  • 29
  • 41
80
votes
6 answers

Add scheme to URL if needed

To create a Uri from a string you can do this: Uri u = new Uri("example.com"); But the problem is if the string (like the one above) doesn't contain the protocol you will get an exception: "Invalid URI: The format of the URI could not be…
Max Favilli
  • 6,161
  • 3
  • 42
  • 62
79
votes
2 answers

NGINX $request_uri vs $uri

How do you determine when to use $request_uri vs $uri? According to NGINX documentation, $request_uri is the original request (for example, /foo/bar.php?arg=baz includes arguments and can't be modified) but $uri refers to the altered URI. If the URI…
teknova
  • 857
  • 1
  • 6
  • 12
75
votes
7 answers

How do I delete files programmatically on Android?

I'm on 4.4.2, trying to delete a file (image) via uri. Here's my code: File file = new File(uri.getPath()); boolean deleted = file.delete(); if(!deleted){ boolean deleted2 = file.getCanonicalFile().delete(); if(!deleted2){ …
Randall Stephens
  • 1,037
  • 1
  • 10
  • 16
71
votes
3 answers

Spider a Website and Return URLs Only

I'm looking for a way to pseudo-spider a website. The key is that I don't actually want the content, but rather a simple list of URIs. I can get reasonably close to this idea with Wget using the --spider option, but when piping that output through a…
Rob Wilkerson
  • 40,476
  • 42
  • 137
  • 192
67
votes
10 answers

How do I pass a datetime value as a URI parameter in asp.net mvc?

I need to have an action parameter that has a datetime value? Is there a standard way to do this? I need to have something like: mysite/Controller/Action/21-9-2009 10:20 but I'm only succeeding indoing it with something…
GilShalit
  • 6,175
  • 9
  • 47
  • 68