Programming for Search Friendly URL’s without RegEx

December 12th, 2006 by Asia

This doesn’t have to be difficult. With some thought, you can easily pull together some simple php code to help create keyword rich url’s without messing with regular expressions.

Many of the websites I design today are dynamic, the difference between my dynamic pages and what’s out there, is that I do not code for regular dynamic URL’s. The use of “?” or “&” and “=” are nonexistent in my .htaccess files. But my web pages offer dynamic content, with search friendly URL’s.

The secret? php function str_replace()

That’s it! Good Luck! Just kidding… All my websites have products, each product has a name and category. I decide my keyword phrases for category directories and use product names to deliver additional keyword rich urls. I run various keyword checks, if you have a list of products, the chances are these products are currently being searched, get their most searched for product name and use it.
Let’s look at a dynamic URL:

http://www.somedomain.com/index.php?id=1&category=widgets

Your code will look something like this:
select * from products where id=1 and category=widgets.
Produce content for product.
Deliver page.
done…
open .htaccess
enter complex regexp

Keyword Rich Version sans .htaccess:

http://www.somedomain.com/widgets/blue-widgets.php

My code looks like this:

$page = str_replace(”-”,” “,$PHP_SELF);
$page = str_replace(”.php”,”",$page);
$page = str_replace(”http://www.somedomain.com/”,”",$page);
list($category,$product)=explode($page,”/”);
select * from products where name=’$product’
Produce content for product.
Deliver page.
done…

That’s it. No complex regular expressions, no worrying about the .htaccess. URL’s are keyword rich. The main difference is unlike mod_rewrite you need to produce more pages. So we go into page production

write all code to a template.php

write php code page createpages.php

select productname from database order by id
while($row=mysql_fetch_object($sql)) {
$page=str_replace(” “,”-”,$row->title);
$page=$page.”.php”;
copy(”template.php”,$page);
}

A lazy girls way to avoiding regexp!

Posted in Search Engine Optimization

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

Contact Linux-Girl