Review App

Internet Entrepreneurs Blog

Search Engine Friendly URLs

February 22nd, 2006

Since most people using hosting services don’t have access to their web server configuration files there isn’t an obvious solution to making urls like info.php?id=14 more search engine friendly. I even recently read on the google sitemap info page that not only does Google dislike dynamic urls like the one above but that google SPECIFICALLY doesn’t like pages that have an id argument with a number. It appears google would prefer a URL like info.php?state=14 to the URL above.

This really annoys me, especially since this is the most logical way to handle large information based websites since most of the data is stored in a database. I’ve already mentioned my trick of converting numbers to letters and I have had success with this method. Here’s my latest trick and you can use this one in combination with the previous trick if you like.

Using PHP’s GLOBAL variables you can keep track of any text tacked onto the end of a url. This allows you to change your info.php?id=14 URL into info.php/14 by using the following code:

$page_g = $GLOBALS[’REQUEST_URI’];
$scriptName = $GLOBALS[’SCRIPT_NAME’];
$scriptName = str_replace(”/”, “/”, $scriptName);
$pattern = “/($scriptName)/i”;
$info_id = preg_replace($pattern, ‘’, $page_g);
$info_id = str_replace(”/”, “”, $info_id);

You can place as many modifiers on the end of the URL, just separate each one with a slash then use the split function to get each of your variables. I think the Wikimedia Wiki also uses this method so it appears to be legit. Good luck!

Leave a Reply