Dynamic Content and Static URLs
SEO at its best!
Search engines will look at Dynamic pages as their own pages (with their own query strings), and index them as such. The advantage to having a Static URL is you can use keywords in the title which well help with your SEO. For instance, if you had an article about global warming, you might want the name to be “http://www.yoursite.com/global-warming.php”. But you don’t want to have to actually create a static page for each of those URLs.
There are two ways of doing this, one better than the other. What I had been doing for a long time is make a static page, then including the dynamic page and passing variables to it. Something like:
<?php
$articleid = 27;
include(“dynamic-page.php”);
?>
The dynamic page is coded to take that variable and then it displays the page. This is definitely better then redoing the code every page, but it can be improved.
.htaccess is the key to this solution. It can only be used on Apache servers as far as I know (sorry to those of you who have a Windows Server). Regular Expressions are also used in .htaccess, and will be in this example. The basis of this solution is you use .htaccess to redirect static links to a dynamic page, but when you redirect the links address doesn’t change. Here’s an example of how you can do that (put this code in your .htaccess file).
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)-a-([0-9]*).php$ /dynamic-page.php?articleid=$2 [L]
Ok, basically says any link to .php that ends with “-a-” (number) “.php” will be sent to your dynamic page, with the query string “articleid=” (number). So, lets say you went to “global-warming-a-27.php” it would redirect the page to “/dynamic-page.php?articleid=27″. Now your page can use that ID to call the right article from the database or wherever you’re storing the article.
That’s it! It’s as simple as that. This will allow you to create static urls, so Search Engines can find them and people can book mark them, but you don’t have to create any extra code.
-Kerry


Leave a reply