{"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":"
<\/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 First, let\u2019s take a look at some of the general principles of URI design.<\/p>\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 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 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 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 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 The URI should be composed of keywords that are important to the content of the page. So, if the URI is for a blog post that has a long title, only the words important to the content of the page should be in the URI. For example, if the blog post is \u201cMy Trip to Best Buy for Memory Cards,\u201d then the URI might be \/posts\/2010\/07\/02\/trip-best-buy-memory-cards<\/span> or something similar. <\/p>\n As a side benefit, using important keywords in the URI will improve SEO. My personal SEO philosophy is that, rather than optimize for search engines, optimize for good content. Search engines have made it their goal to find the best content on the web, so doing everything possible to create an easy-to-use site with great content and opportunities for further information (links) will, in my opinion, yield the best long-term results for search engine visibility.<\/p>\n We have covered some of the guiding principles behind URI design. Now, let\u2019s look at some technical implementations of those guidelines.<\/p>\n The URI should not have .html, .htm, .aspx (a big annoyance), or anything else attached to it that is only designed to show the underlying technology. No end user cares that your site was written in ASP.NET (.aspx), ColdFusion (.cfm), or uses Server Side Includes (.shtml) – or at least most end users don\u2019t. The extra info is just extra typing and extra room for error and frustration.<\/p>\n The one exception to this rule is appending a URI with a postfix like .atom, .rss, or .json to request that the certain format be returned. Alternatively, the format could be requested with the Accept HTTP header.<\/p>\n The www. should be dropped from the website URI, as it is unnecessary typing and violates the rules of being as human-friendly as possible and not including unnecessary information in the URI.<\/p>\n Many users, however, will still type in the www. prefix, so www.domain.com<\/span> should 301 redirect to domain.com<\/span>. The same goes for 301 redirecting www.subdomain.domain.com<\/span> to subdomain.domain.com<\/span>.<\/p>\n URIs should be in the format:<\/p>\n domain.com\/[key information]\/[name]\/?[modifiers]<\/span><\/p>\n Key information is information that is not the object identifier (like the post title), but is still key to the object being accessed. This may include:<\/p>\n Modifiers modify the view, not the data model being represented, and thus they are part of the query string and not the URI itself.<\/p>\n The amount of “key information” should be kept to a minimum, as URIs should not be overly nested. Each item placed in the key information section must really be key to addressing the page.<\/p>\n In the end, the URI should represent a descending hierarchy. For example<\/p>\n Example: http:\/\/domain.com\/posts\/servers\/nginx-ubuntu-10.04<\/span>. In the case of items with dates, the format should follow the descending hierarchy:<\/p>\n Example: http:\/\/domain.com\/news\/tech\/2007\/11\/05\/google-announces-android<\/span>.<\/p>\n Google News has some interesting requirements<\/a> for webpages that want to be listed in the Google News results – Google requires at least a 3-digit unique number. Due to the fact that they will ignore numbers that look like years, a 5 or more digit number is preferred. Also recommended is a Google News sitemap<\/a>. This is one of those cases where if you absolutely must target Google News, you must conform to this inferior URI structure. But, if you must, make sure that you are consistent and that it is still hackable (for example, use the format yyyymmdd like 20100701<\/span>).<\/p>\n All characters must be lowercase. Attempting to describe a URI to someone when mixed case is involved is next to impossible.<\/p>\n If someone types the URI in mixed-case, they should be 301 redirected to the lowercase page. That sounds really nice, but in practice, I\u2019m not exactly sure if that is possible… using a CMS that rewrites all requests to a single file would be the easiest way to accomplish it as the script could issue the 301 to lowercase, but I\u2019m not sure if there\u2019s an easier way (.htaccess rules or something).<\/p>\n Actions may be appended to the URI, like show, delete, edit, etc. Non-destructive actions (those that do not change the object) should be requested with a HTTP GET, while destructive actions should be POSTed to the URI. Run a Google search for REST URI Design for more information.<\/p>\n A URI might contain the title of a post, and that title might contain characters that are not URI-friendly. That post title must therefore be made URI friendly. For example<\/p>\n Characters can be URI escaped (like %20 for the space character), but this is generally a bad idea for many of the above reasons (shows technology, unnecessary typing, etc.)<\/p>\n Use a sentence like structure (credit to Chris Shiflett<\/a>): <\/p>\n chriscoyier.net\/authored\/digging-into-wordpress\/<\/span> jacobwg.com\/thinks\/this-post\/is\/basically-done<\/span><\/p>\n If you know of any more URI guidelines that I missed or have any comments about those I did remember, I\u2019d love to hear them!<\/p>\n Many thanks to the Forrst<\/a> community who saw the initial (very) rough drafts of this post and contributed many insightful comments. Special thanks to @chriscoyier<\/a>, @caludio<\/a>, @steerpike<\/a>, and @mattthehoople<\/a> for directly contributing to the guideline list and to all the other Forrst commenters for providing helpful discussion.<\/p>\n Thank you to my dad for proofreading and review! Thank you also to Chris for being kind enough to offer to post this on CSS Tricks!<\/p>\n","protected":false},"excerpt":{"rendered":" This is a guest post by Jacob Gillespie who started an interesting thread on Forrst about this topic. I invited him to post it here, to which he graciously accepted. 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 […]<\/p>\n","protected":false},"author":248441,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"c2c_always_allow_admin_comments":false,"footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":[]},"categories":[19,4],"tags":[419],"jetpack_publicize_connections":[],"acf":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"featured_media_src_url":null,"_links":{"self":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/posts\/6949"}],"collection":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/users\/248441"}],"replies":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/comments?post=6949"}],"version-history":[{"count":16,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/posts\/6949\/revisions"}],"predecessor-version":[{"id":253723,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/posts\/6949\/revisions\/253723"}],"wp:attachment":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/media?parent=6949"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/categories?post=6949"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/tags?post=6949"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}Principles<\/h3>\n
A URI must represent an object, uniquely and permanently<\/h4>\n
Be as human-friendly as possible<\/h4>\n
Consistency<\/h4>\n
“Hackable” URIs<\/h4>\n
\n
Keywords<\/h4>\n
Technical Details<\/h3>\n
No evidence of the underlying technology<\/h4>\n
No WWW<\/h4>\n
Format<\/h4>\n
\n
\n
\n
All lowercase<\/h4>\n
Actions appended to the URI<\/h4>\n
URI identifiers should be made URI friendly<\/h4>\n
\n
Fun idea<\/h4>\n
\nchriscoyier.net\/has-worked-for\/chatman-design\/<\/span>
\nchriscoyier.net\/likes\/trailer-park-boys<\/span><\/p>\nCredits<\/h3>\n