More than a year back I had written a tutorial on creating SEO Friendly URLs with Mod Rewrite and PHP, where I had explained the basic SEO concepts of rewriting URLs to make them SEO friendly.
Though It has been over a year, numerous emails and comments have dropped in for me to write the second part of the series, so here it is :-)
In the first part I had explained the basic changes you would require to do in the .htaccess file to create SEO friendly URLs, the post explained how you can internally redirect a URL to any PHP page that is stored on your web server.
In this post I will explain how you need to modify the PHP files so that it will generate the SEO friendly links for your website.
The original URL we were dealing with would create URLs as this one http://www.yoursite.com/product.php?productid=2&categoryid=3, here is a example PHP code of that generates this URL. I am leaving the Database connection code out of the example to keep the examples short.
In order to generate SEO friendly links you will have to change the way you write the links to the page, the changes are pretty minor and here is the example code for writing the SEO friendly URLs on your pages with PHP.
In the code example, I changed the URL structure to match what we created in the .htaccess file, I am changing the product title to SEO friendly version by calling the method gen_seo_friendly_titles which takes the product title as a parameter.
The gen_seo_friendly_titles method basically lower cases the product name and replaces spaces and dashes to form a proper URL. You can use your own replacements in the method as you see it fit.
Also as you can see I am not directly manipulating the $product_title itself and saving it in another variable called $product_title_url, since we will be using the $product_title as the anchor text and would want it to remain as it is.
This concludes the series of creating SEO friendly URLs with Mod Rewrite and PHP, hopefully this should answer the many emails and comments about where the second part is :-), feel free to drop your question in the comments.