Which URL is Right?

Share this article

Following Andrews’s look at good hyperlink text last week, Steve wrote in to ask about the other side of the hyperlink equation: URLs.

Steve writes,

How about starting a crusade to standardize URLs?

http://www.example.com
http://www.example.com/
http://www.example.com/index
http://www.example.com/index.html
http://example.com
http://example.com/
http://example.com/index
http://example.com/index.html

WHICH ONE IS CORRECT??

Steve

Good question, Steve! First of all, these pairs are equivalent:

  • http://www.example.com
  • http://www.example.com/
  • http://example.com
  • http://example.com/

The trailing ‘/’ is implied if there is no path specified, so you can use either form freely. In the same way, the port number (80) is implied in most URLs, but you could quite correctly spell it out:

  • http://www.example.com:80
  • http://www.example.com:80/
  • http://example.com:80
  • http://example.com:80/

Best practice is to leave off the port number when it is 80, of course. As for whether to leave off the path when it is ‘/’, that’s a matter of personal preference. Some will argue that leaving off the ‘/’ saves a byte on an Internet crowded with bytes. Others will argue that including the ‘/’ makes it clear to readers that you’re referring to the home page of the site in question, as opposed to the site as a whole.

Next we have the question of whether to include a ‘www.’ at the start of the hostname. This is a rather controversial subject that we covered at length in Tech Times #184. In short, including the ‘www.’ is a nod to Web tradition, whereas leaving it off is bowing to current Web fashion.

Strictly speaking, neither is incorrect. Pick whichever suits you best. The important thing is to make sure that the other form automatically redirects to the form you have chosen. If your server answers to both forms without redirection, search engines will see your site as two separate sites (one with the ‘www.’ and one without), each of which will have a lower search engine ranking than if your site had a single, authoritative hostname.

You can find instructions to set up your web server to redirect to your preferred hostname at the no-www advocacy site. From its name you can tell which URL style it prefers!

As for the URL of the home page (/, /index, or /index.html), again that is largely a matter of personal style, and again the key is to choose one and make sure that the others either redirect to your preferred form, or display a 404 error page. This ensures that search engines don’t mistake them for multiple copies of the same page at different addresses.

How do you like your URLs? Trailing slash or no? ‘www.’ or no ‘www.’? Let me know by leaving a comment!

Frequently Asked Questions (FAQs) about URLs

What is the difference between a URL and a URI?

A URL (Uniform Resource Locator) is a specific type of URI (Uniform Resource Identifier). A URL not only identifies a resource but also explains how to access it by specifying its primary access mechanism or network location. For example, the URL http://www.example.com specifies the use of HTTP (Hypertext Transfer Protocol) to access the resource. On the other hand, a URI is a string of characters used to identify a name or a resource on the Internet. It does not necessarily provide information on how to access the resource.

Why is the structure of a URL important?

The structure of a URL is crucial because it helps in organizing and locating web resources efficiently. A well-structured URL can provide both humans and search engines an easy-to-understand indication of what the destination page will be about. It can also improve the user experience by making it easier to copy and paste the URL, remember it, or type it.

What does a URL consist of?

A URL typically consists of several parts, including the protocol, domain name, path, and query string. The protocol (like HTTP or HTTPS) indicates how the resource will be retrieved. The domain name identifies the server where the resource is located. The path specifies the specific page or file on the server, and the query string can provide additional information to be passed to the server.

What is the difference between HTTP and HTTPS in a URL?

HTTP stands for Hypertext Transfer Protocol, and HTTPS stands for HTTP Secure. The main difference between the two is that HTTPS uses an SSL (Secure Sockets Layer) certificate to establish a secure encrypted connection between the web server and the browser, whereas HTTP does not.

How does a URL affect SEO?

URLs play a significant role in SEO. Search engines like Google use URLs to understand the content of the page. A well-structured, descriptive URL can help improve your page’s ranking. It’s also important to note that URLs are displayed in search results, and a clear, descriptive URL can encourage users to click on your page.

What is a URL redirect?

A URL redirect is a way to send both users and search engines to a different URL from the one they originally requested. This can be useful when the original URL has been changed or deleted.

What is a URL shortener?

A URL shortener is a tool that takes a long URL and turns it into a shorter one. This can be useful for sharing links on social media or in other places where a long URL might be unwieldy.

What is a relative URL?

A relative URL refers to a location that is relative to the current page. For example, if you’re on the page http://www.example.com/about, a relative URL of /contact would take you to http://www.example.com/contact.

What is a canonical URL?

A canonical URL is the URL that you want visitors to see and search engines to index. This can be important when you have multiple URLs pointing to the same content, to avoid duplicate content issues.

How can I create a good URL?

A good URL is short, descriptive, and easy to read. It should include keywords that describe the content of the page, and avoid unnecessary punctuation and special characters. It’s also a good idea to use hyphens to separate words, as this can make the URL easier to read for both humans and search engines.

Kevin YankKevin Yank
View Author

Kevin Yank is an accomplished web developer, speaker, trainer and author of Build Your Own Database Driven Website Using PHP & MySQL and Co-Author of Simply JavaScript and Everything You Know About CSS is Wrong! Kevin loves to share his wealth of knowledge and it didn't stop at books, he's also the course instructor to 3 online courses in web development. Currently Kevin is the Director of Front End Engineering at Culture Amp.

Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week