Using a database to dynamically create web pages makes for a much improved site in many ways. However, such URLs are not very search engine friendly. Search engines are much better at indexing static pages, and don't do a good job of following hyperlinks that contain query strings. The advantages of a dynamic site are overwhelmingly obvious--so what is to be done? With a little extra effort, you can create a dynamic site that is easily crawled by webbots.
If your URL is relative, rather than absolute, change it to an absolute URL and then copy it to the clipboard. You will have a much clearer understanding of what’s happening if you do it this way. Now open your browser and go to webmaster-toolkit.com.
[Editor's note: A great resource for Search Engine Optimization techniques and tools can be found at http://www.seochat.com.]
Take a moment to appreciate what is available here. I’m sure you’ll want to return, so bookmark the site.
On the left, under the “SEO Tools” heading find and click the link “Rewrite Rule Generator”. Scroll down until your screen looks like this:
Now paste your dynamic URL into the appropriate textbox and decide if you want to represent your dynamic URL as a page or a directory. It’s up to you but make sure that you don’t create a directory name that matches an existing directory and that you don’t generate a page name that is longer than 255 characters. If you choose to generate a page name set the appropriate radio button and enter a page name into the textbox (something that best describes your page). We will be using the page name style of static URL in our examples. Click the generate button and you should have your .htaccess file in seconds. Copy the returned text area and paste it into your favorite text editor. The text returned when entering the word “type” into the page named textbox and using our example URL,
+FollowSymLinks RewriteEngine on RewriteBase / RewriteRule type(.*)-(.*).htm$ /main.php?category=$1&subject=$2
This is all you will need for your .htaccess file. This file will intercept all page requests within the directory in which it is located and convert specified URLs with a static format to ones using a query string. That may sound like the opposite of what you want to achieve. Read on and things will become clearer.
As promised, you’ve now created a .htaccess file without any reference to regular expressions. Don’t leave the webmaster-toolkit site just yet. Have a look at what the rewritten URL should be. Our example looks like this: