Page:Aaron Swartz s A Programmable Web An Unfinished Work.pdf/24

12 '''2. BUILDING FOR USERS: DESIGNING URLS''' Thus, the term was changed to URI, Uniform Resource Identiﬁer, to encompass this wider set. I stick with the term URL here since it’s more familiar, but we’ll end up discussing abstract concepts in later chapters.)

First, URLs shouldn’t include technical details of the software you used to build your website, since that could change at any moment. Thus, things like “.php” and “.cgi” are straight out. For similar reasons, you can drop “.html”, “PHP_SESS_ID” and their ilk. You’ll also want to make sure that the names of your servers (e.g., “www7.example.org” or “plato.example.net”) aren’t seen in your URLs. Moving from one programming language, one format, or one server to another is fairly common; there’s no reason your URLs should depend upon your current decision.

Second, you’ll want to leave out any facts about the page that might change. This is just about everything (its author, its category, who can read it, whether it’s ofﬁcial or a draft, etc.), so your URLs are really limited to just the essential concept of a page, the page’s essence. What’s the one thing that can’t be changed, that makes this page this page?

Third, you’ll want to be really careful about classiﬁcation. Many people like to divide their websites up by topic, putting their very favorite recipes into the ‘/food/‘ directory and their stories about the trips they take into ‘/travel/‘ and the stuff they’re reading into ‘/books/‘. But inevitably they end up having a recipe that requires a trip or a book that’s about food and they think it belongs in both categories. Or they decide that drink should really be broken out and get its own section. Or they decide to just reorganize the whole thing altogether.

Whatever the reason, they end up rearranging their ﬁles and changing their directory structure, breaking all their URLs. Even if you’re just rearranging the site’s look, it takes a lot of discipline not to move the actual ﬁles around, probably more than you’re going to have. And setting up redirects for everything is so difﬁcult that you’re just not going to bother.

Much better to plan ahead so that the problem never comes up in the ﬁrst place, by leaving categories out of the URL altogether.

So that’s a lot of don’ts, what about some do’s?

Well one easy way to have safe URLs is to just pick numbers. So, for example, your blogging system might just assign each post with a sequential ID and give them URLs like:

http://posterous.com/p/234