Creating User-Friendly URLs 08-05-2004
The web is rampant with crude looking URLs largely due to the increase of dynamically generated web pages. Not only do these URLs look poor visually they decrease a site’s usability and become less attractive to search engines for ranking.
I’ll take a look at why these URLs are a problem and how they can be fixed to present a friendlier user experience and improve your search rankings.
Usability of URLs
Ever try to tell someone a URL over the phone or attempt to write down a specific URL? Aside from the domain name, things can get real hairy after that first trailing slash. Somewhere along the line, we as developers have seemed to forget what the URL is supposed to tell the user.
In basic terms, the URL is an address and we can learn a lot from comparing a URL to a street address. The street address has a structure which for the most part has been standardized and shows meaning in it’s presentation. I can read it off to a person over the phone and they too will understand it. I can also easily remember a street address as well.
I’m not saying that we need to standardized our URL structure across the board but to remember that there is meaning in structure. The URL presents a hierarchy which informs users about the information which they are viewing.
In working on TheDatingFile.com we had to deal with this very problem in particular. For example we used to have the URL shown below:
http://www.thedatingfile.com/info.php?id=4&file=straight
What does that mean? Not much to the user. Forget about attempting to type that in yourself from memory. Actually forget about even looking at it. Once the question marks and ampersands begin to appear it looks less like information and more like code.
After implementing web server features, which I’ll discuss later, here is the result:
http://www.thedatingfile.com/straight/yahoo/
This URL now actually provides the user with some information. The hierarchy is used to present the user with not only a simple overview of the content of the page but also their location in the web site.
Further Reading:
- Jakob Nielsen’s Alertbox URL as UI
- Adam Baker’s Theory: How to make URLs user-friendly
- IBM DevelopWorks: Making URLs accessible
Search Engines and Friendly URLs
Google says it best in their Information For Webmasters:
We are able to index dynamically generated pages. However, because our web crawler can easily overwhelm and crash sites serving dynamic content, we limit the amount of dynamic pages we index.
Many search bots see dynamic pages as endless loops of links or blind alleys. Which many times is not the case. From a developer’s stand point, making dynamic pages can save tons of time but unfortunately search engines impose a penalty for that. Luckily there is a solution, Apache’s mod_rewrite.
Make Your URLs Friendly
Mod_rewrite has a lot of features ranging from easy to implement to the more complex. Shown below is how we made our URLs for TheDatingFile.com more user-friendly and optimized for search engines.
The following code is contained In our .htaccess
file stored at the root level of the site:
RewriteEngine On<br /> RewriteRule ^(.*)/(.*)/$ /info.php?file=$1&shortname=$2 [L]
A brief explanation of what is actually going on here. We start off by telling the Apache web server to turn on mod_rewrite. The RewriteRule
is what will do all the work in transforming our URLs. “^(.*)/(.*)/$
” is the format in which we wish to have our URLs displayed. “(.*)
” will match anything and put the contents, starting with $1
, into the variable (file=$1
) of our real dynamically generated page.
Further Reading:
- DevShed: Make Dynamic URLs Search Engine Friendly
- Webmaster Toolkit: mod_rewrite RewriteRule Generator