{"id":6949,"date":"2010-08-02T05:42:35","date_gmt":"2010-08-02T12:42:35","guid":{"rendered":"http:\/\/css-tricks.com\/?p=6949"},"modified":"2017-04-13T18:11:35","modified_gmt":"2017-04-14T01:11:35","slug":"guidelines-for-uri-design","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/guidelines-for-uri-design\/","title":{"rendered":"Guidelines for URI\u00a0Design"},"content":{"rendered":"
This is a guest post by Jacob Gillespie<\/a> who started an interesting thread on Forrst<\/a> about this topic. I invited him to post it here, to which he graciously accepted.<\/div>\n

\"\"<\/p>\n

Over the past several years, I have taken an interest in usability and web design. One of the areas that seems to be often overlooked when it comes to design of a site is the design of the URI<\/acronym>s on that site. Modern CMS<\/acronym> systems allow for varying degrees of URI customization, but the defaults are often not as usable as they could be, and URIs are often placed last in the design process.<\/p>\n

Clean URIs are one component of a clean website, and it is an important one. The majority of end-user access to the Internet involves a URI, and whether or not the user actually enters the URI, they are working with one nonetheless.<\/p>\n

First, I would like to talk about the guiding principles behind URI design, then talk about the practical implementation of the principles.<\/p>\n

<\/p>\n

Note: Originally, I wrote this article draft using the term \u201cURL,\u201d but since \u201cURL\u201d has been mostly deprecated by \u201cURI,\u201d I\u2019ve updated to use the term URI. More information from W3C<\/a>.<\/p>\n

Principles<\/h3>\n

First, let\u2019s take a look at some of the general principles of URI design.<\/p>\n

A URI must represent an object, uniquely and permanently<\/h4>\n

One of the most fundamental philosophies behind a URI is that it represents a data object on the Internet. The URI must be unique so that it is a one-to-one match – one URI per one data object. <\/p>\n

While this is always the goal, there are times at which it is very difficult or impossible to accomplish. Canonical URL tags were invented to help reduce the amount of duplicate content seen by a search engine. While not a final solution, canonical URLs are strongly recommended as large search engines like Google are now paying attention to them. For more information about canonical URLs, check out this article by SEOmoz<\/a>.<\/p>\n

URIs should also be permanent (i.e. choose the URI once and leave it at that). This speaks to good URI design before a site is launched, with the URIs being carefully planned. There will come a time when you do want to make improvements to your choices or otherwise must change URI structure. When this becomes a necessity, be sure to set up HTTP 301 moved permanently<\/a> redirects on your server. This tells browsers and search engines the new location of the content and will also preserve any PageRank<\/a> that the old URI has accumulated.<\/p>\n

Be as human-friendly as possible<\/h4>\n

This is the most fundamental driving factor behind URI design (or it should be). URIs should be designed with the end user in mind. Search Engine Optimization (SEO) and ease of development should come second.<\/p>\n

One way to keep a URI user-friendly is to keep it short and to the point. This means using as few characters as possible while still maintaining usability. So, \/about<\/span> is better than \/about-acme-corp-page<\/span>. While striving to be as short as possible, it should not sacrifice that user-friendliness by using URIs like \/13d2<\/span> as this holds no meaning for the end users.<\/p>\n

Conversely, using a shortlink<\/a> whenever sharing a URI is encouraged. This is great for tweeting links on Twitter, or otherwise sharing on social sites like Facebook or Google Buzz. It is great if you can control your own URI shortener for SEO reasons, although a site like Bit.ly is good too. I personally use PrettyLink Pro<\/a> (a WordPress plugin) to create my short URIs. An alternative is the Short URL plugin<\/a>.<\/p>\n

\n\"\"<\/p>\n

WordPress provides a button to get a shortlink to a post based on WordPress’ own \/?p=XXX<\/span> format which is likely to be shorter than your chosen permalink structure. The advantage being that will work as long as your site is around. The disadvantage is the shortness of the link is dependent on the length of your domain name.<\/p>\n<\/div>\n

The URI should not rely on information that is not important to the content or the user. A common example of this is using the database ID as the URI, as in \/products\/23<\/span>. The end user does not care that the product is database record number 23, so a URI like \/products\/ballpoint-pen<\/span> is much better. It can be tempting to resort to such poor URI structure as it is often easier on the backend to query the database with an ID rather than have to do a lookup on an alias to find the object.<\/p>\n

One good test to see if a URI is a user-friendly URI is the “speech-friendly” test. You should be able to mention a URI in a conversation with a friend, and it should make sense. For example:<\/p>\n

My bio\u2019s at domain dot com slash jim<\/p><\/blockquote>\n

instead of<\/p>\n

My bio\u2019s at domain dot com slash page slash g g 2 3<\/p><\/blockquote>\n

Consistency<\/h4>\n

URIs across a site must be consistent in format. Once you pick your URI structure, be consistent and follow it! Having good URI structure for part of the site means that you still have poor structure overall. In order for a user to trust that URIs work a certain way on a site, the format must be consistent. If you must switch structure (maybe you\u2019re updating a poorly-designed site), use 301 redirects as previously mentioned.<\/p>\n

“Hackable” URIs<\/h4>\n

Related to consistency, URIs should be structured so that they are intelligibly “hackable” or changeable. For example, if \/events\/2010\/01<\/span> shows a monthly calendar with events from January 2010, then:<\/p>\n