Blog

The thoughts, opinions, happenings, and just plain ramblings of a seemingly boring person.

Christmas 2010 Coding: Friendly URLs and Page Titles

Hello, my URL is now friendlyChristmas 2010 was a pretty standard affair in the end: Church followed by a whole day of visiting family's places. I guess the only big difference is that my parents being away for Christmas made it feel a bit different than normal.

After getting home yesterday evening, rather than vegging out as usual after the big day, i felt in the mood to get something done.

I was in the mood to do some coding/programming, and it usually happens about once a year (the last time being when i added comment notifications to this blog). I've been wanting to do it for a while, but hadn't really been bothered up until yesterday: modify this blog script for it to have friendly URLs and proper page titles.

Most people wouldn't really even notice, but as a geek that is aware of SEO (Search Engine Optimisation) and good web-standards, it always irked me that the original developer of the script had one static page title for the whole blog (i.e. for this blog it was always 'LucasCosti.com - Blog' no matter what page/entry you were viewing), and that it had ugly URLs (i.e. http://lucascosti.com/blog/index.php?entryid=749).

So last night I put my coding hat on and 'hacked the mainframe' (lols) to firstly enable this blog script to have better page titles depending on what context is being viewed (e.g if viewing a specific entry, it would have that entry title in the HTML page title which you can see in your browser's window/tab label).

Secondly (and a whole lot more challenging), this blog now has friendly URLs. For example, whilst previously the direct link to this specific entry would have been an ugly http://lucascosti.com/blog/index.php?entryid=749, it can now be accessed by the 'friendlier' URL of http://lucascosti.com/blog/2010/12/christmas-2010-coding-friendly-urls-and-page-titles-e749/.

This was accomplished relatively easily by using Apache's mod_rewrite in order to rewrite URLs requested to the server. The hard part was modifying the blog script to pump out the friendlier URLs on the page, as well as to not have all the existing relative links to images and existing entries break. Because it's just a URL rewrite happening in the background, all the old permalinks to specific entries and views still work fine.

The new URLs aren't perfect (you've probably noticed the entry ID is still at the end of it), but it really was too much effort to go that step further of having it without it (as it would have necessitated performing a database search to actually 'search' for the correct entry by the title given in the URL, rather than just retrieving it based off its ID as it is now).

Overall I'm pretty happy with the end result; it's kept my PHP/web-programming skills fresh, and given me extra experience in using mod_rewrite which I haven't really used much before now.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.