Make Dynamic URLs Search Engine Friendly - Create an .htaccess File
(Page 3 of 7 )
Open the source code of a page on your site and find an URL with a query string similar to the following:
http://www.mysite/main.php?category=$category&subject=$subject
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,
http://www.mysite/main.php?category=$category&subject=$subject
is as follows:
Options
+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:
http://www.mysite.com/type\$category-\$subject.htm
Copy it into a text file, remove the backslashes that precede each dollar sign and save it to a text file called format.txt. You’ll need this when revising your PHP scripts.
Next: Upload .htaccess to Your Server >>
More Web Services Articles
More By Peter Lavin