administration mode
Pssst...Ferdy is the creator of JungleDragon, an awesome wildlife community. Visit JungleDragon

 

JungleDragon friendly URLs »

FERDY CHRISTANT - JUN 7, 2010 (06:26:01 PM)

Last week I spent an entire week of leave on JungleDragon development. This week I will be sharing the progress in little bits and pieces. Today's topic is friendly URLs.

Friendly URLs are considered to be quite important nowadays, and for good reasons:

  • SEO (Search Engine Optimization). The more descriptive your URL, the better the indexing.
  • Usability. Friendly URLs are more usable, recognizable and memorable by users, also in bookmarks and print.
  • Architecture. Friendly URLs can hide the back-end technologies used for the web application. 

Luckily, the framework that I am using to develop JungleDragon (CodeIgniter) supports friendly URLs out of the box. For example, a URL like this...

http://www.jungledragon.com/image/view/123456

Will call the "View" method of the "Image" controller and pass in the value "123456". All of this is default behavior, which can be overruled and refined in the routes file. From there it is easy to make the above URL slightly better:

$route['image/(:any)'] = "image/view/$1";

This makes the URL look like this:

http://www.jungledragon.com/image/123456

We have gotten rid of the unneccessary "View" URL segment. For long I stopped here. I knew it would be better to include the image title in the URL, but I had this unexplained worry that it would take a lot of effort to encode and decode that title to look up images, especially considering I am supporting UTF8.

This post from Jake Howlett was a breakthrough in my thinking. There is no need to substitute the numeric id with the title to look up images. We can simply combine them like so:

http://www.jungledragon.com/image/123456/eagle-in-mid-air.html

This can easily be accomplished with the following routing rules:

$route['image/(:any)/(:any).html'] = "image/view/$1"; 
$route['image/(:any)'] = "image/view/$1";
 

Basically, these rules say: "I do not care what you place behind the image id, the image id will always be used as the lookup key". Therefore we can place the image title behind the key to create truly friendly URLs. Note that in CodeIgniter, there is a function to create URL safe titles: url_title().

I have implemented the above URL scheme for images, tags, users, pages and classes.

Share |

Comments: 2

COMMENT: BAS PETERS

JUN 8, 2010 - 02:08:32 PM

comment » I have been using the id and description methodology for a while and it works brilliantly. Apart from the benefits you mentioned above, there is also the added benefit that most search engines and crawlers are sensitive to the extension of the webserved filename. When encountering .html the crawler assumes a static page, which has much more chance to be indexed in the first place.

There is however a caveat, since the human readable information in the url is ignored. This part can be misused for spoofing. Take for example a link to a news article on a well known dutch news site:

http://www.telegraaf.nl/digitaal/mobiel/6882355/Ferdy_is_very_happy_with_his_android_powered_mobile.html

One could alter the description completely in the url and have it indexed this way, just because the page ignores it

Now consider this link to an article on another well known dutch news site:

http://www.nu.nl/gadgets/2264558/ferdy-still-likes-his-android-phone.html

Much better, because the website recognises the url as being "wrong" and forces a redirect to the "proper" url. Search engines will respect the 301 Permanent Redirect that you should code in the webpage logic and only index the new and proper url.

The latter still does not prevent people from willfully manipulating the url and putting the url up on the internet for people to click on. Ofcourse you could check if the human readable description matches exactly with your description in the model of your application. But is that worth the performance penalty? In my opinion: no. Or rather, it depends on the type of web application.

As a last remark, to help Google index your pages correctly, it is advisable to use the sitemap.xml methodology found in the Google Webmaster toolkit. «

COMMENT: FERDY

JUN 8, 2010 - 19:33:21

comment » Bas,

Thanks for the extra info. I agree with you that it is not worth the performance penalty and hassle to use the title as a lookup key, although for some applications it might be worthwhile.

I will definitely look into more SEO strategies once I am closer to production. «

RATE THIS CONTENT (OPTIONAL)
Was this document useful to you?
 
rating Awesome
rating Good
rating Average
rating Poor
rating Useless
CREATE A NEW COMMENT
required field
required field HTML is not allowed. Hyperlinks will automatically be converted.