In a URI, the authority component names the server that holds the resource. It sits after the scheme and its two slashes, and before the path. Take this address:
https://[email protected]:8080/blog/post?ref=mail#comments
Here the authority is [email protected]:8080. The scheme is https, the path is /blog/post, the query is ref=mail and the fragment is comments. For everyday web addresses, the authority is just the hostname, so people usually call it "the domain".
The three parts
The standard for URIs, RFC 3986, writes the authority as [userinfo@]host[:port]. Only the host is required.
- Host. A domain name such as
www.example.comor an IP address such as192.0.2.10. A domain with non-ASCII letters is written in an ASCII form called Punycode when it travels in a URL. - Port. The number of the "door" the server listens on, after a colon. Web addresses usually leave it out, because HTTP defaults to 80 and HTTPS to 443. A server on any other port, such as
localhost:8080during development, needs it spelled out. - User info. An optional name before an
@. It's rare on the web, and the olduser:password@form is deprecated in the standard.
Where it starts and ends
The authority starts right after // and runs to the next /, ? or #, or to the end of the URI RFC 3986. If there are no two slashes, there is no authority.
Some schemes never have one: mailto:[email protected], tel:+1-816-555-1212 and urn: names name a thing without naming a server. File URIs often have an empty authority, which is why they show three slashes: file:///etc/hosts.
One server, several spellings
Several authorities can point to the same site, and that matters for SEO, because search engines see different URLs:
- Case. The host is case-insensitive, so
WWW.Example.comandwww.example.comare the same server. Write hosts in lowercase. - Default ports.
https://www.example.com:443/andhttps://www.example.com/are the same address. The standard says to leave out a default port. - With or without www.
example.comandwww.example.comare different hosts. They can serve different content, so search engines treat them as separate URLs.
Pick one form, redirect the others to it and use that form in links, sitemaps and canonical tags. The article on URL canonicalization covers the details.
Why user info in a URL is a risk
A password in a URL can end up in browser history, bookmarks and server logs. MDN advises against user information in HTTP URLs and points to HTTP authentication or session cookies instead.
The @ also makes a classic phishing trick work. In https://cnn.example.com&[email protected], everything before the @ is user info. The real host is 10.0.0.1 MDN. When a link looks odd, read what comes after the @: that's the host.
Fixing "URI has an authority component"
Developers meet the term most often in this Java error:
java.lang.IllegalArgumentException: URI has an authority component
It comes from new File(URI). That constructor accepts only an absolute file: URI with a path and no authority, query or fragment Java docs. A URI such as file://fileserver/projects/app has fileserver as its authority, so the constructor refuses it.
The usual cause is a project, library or config path on a network share, written as a UNC path like \\fileserver\projects\app. Tools that turn that path into a URI put the server name into the authority. Two ways out:
- Move the project to a local disk, or map the share to a drive letter and point the tool at that path.
- In your own code, check where the URI comes from and build the
Filefrom a plain local path instead of afile://server/...URI.
If the error appears during a build or deployment, search the configuration files for paths that start with \\ or file:// followed by a server name.