User Name:
Password :  

Optimizing Dynamic Webpages

  [locked]


I've been using the Google Toolbar with Firefox for some time, but only recently did I notice the low PageRank score on the toolbar for ralford-dot-net. The score is usually a 1/10, but I've seen it dip as low as 0/10 during weeks with more updates.

I've heard that dynamic pages have more trouble getting good search engine scores than static pages, but I've never looked into it. I've actually heard some people using this as an accuse to keep them from making the transition to a dynamic webpage. Of course, search engine optimization is an important factor in the success of any website. But it's one that is often overlooked for weeks until someone notices that traffic to their site still hasn't picked up. This is my case.

As I tweak the code behind ralford-dot-net to make it appear as a set of static webpages, I'll be listing any useful resources I find below. Eventually, this wiki entry should have a pretty detailed explaination of the steps to make a dynamic webpage appear as a set of static pages.

The Problem


Apparently, search engines will often ignore the "?" and "=" characters in a URL because they don't want to get "trapped" in a huge website full of dynamic links (Optimizing the Ranking of Dynamic Website). If you read the referenced article, there are a couple of work-arounds: software packages, CGI/Perl scripts, and the Apache module 'mod_rewrite'

Perl is foreign to me, and I don't like the idea of extra software, so the method I will focus on is based around the Apache server configuration. Fortunately, Apache has this module called 'mod_rewrite' that can be used to change the appearance of characters like "?" and "=" in your website's URLs.

Apache's Mod-Rewrite Module


You may be tempted to jump into the '.htaccess' file without first enabling the mod_rewrite module on your Apache server (as was I). If it's not enabled, you'll see an evil 500 Internal Server Error page. To enable it, edit 'httpd.conf', and make sure the rewrite_module is not commented out (with a #). It should read as: If you can't find 'httpd.conf', you're screwed. No, actually it should be sitting in: Apache/conf. On mine, the line to uncomment was line 164. Save the file when you're done, and make sure you restart Apache.

Your server should now be ready for you to edit '.htaccess'.

.htaccess


The .htaccess file lets your server 'decode' a static URL pattern and replace it with a URL containing with variables and whatever else is needed for your dynamic website to pass variables (usually "?" and "="). It uses user defined rules which allow the server to do pattern matching if the mod_rewrite module is turned on in Apache.

An example .htaccess file looks like the following:
RewriteEngine On
RewriteRule ^fruits_(.*).html fruits.php?num_apples=$1
The first line turns on the mod_rewrite module in Apache. If you attempt to do this without enabling use of the module in 'httpd.conf', you'll get nasty internal server errors.

The second line is an example of a rule. It tells the server that any time a user (or bot) browses to a static URL in the form of "fruits_46.html", take them to "fruits.php?num_apples=46" instead. The goal is that search engines will see a static URL and crawl to the link, but when the search engine gets there, your server can still pull information from a database if it needs to.

Just to note, the rule used in this example is fairly simple, and more complicated rules can be written.

So Now What


After this is all set up, when you write a URL in your PHP or HTML code, it should be written as the static URL pattern so search engine bots will want to visit it. Of course, you're not required to use the pattern. The normal way of passing variables will still work, but you want to maximize your page rank so potential visitors will be able to find your site through a search engine.

Resources


Here's a couple of resources I found when I was learning how to optimize dynamic webpages:
Ralford.net Before and After the Modification


I took some snapshots in Webstats to show that the mod-rewrite modification actually works. This image before the modification only shows the index file for Ralford.net:
After implementing the change, you can see that my visitors' browsers have visited quite a few static URLs:

dfkj31sk342