I was recently into the using cryptic GET querystrings to access back end database information with dynamic web pages. Using PHP and classic ASP as well as .NET are perfect languages for the typical users.php?user=YOURusername. Of course, in PHP, you can use the typical $_GET['user'] code to access this value. However, what if you are using ID numbers? A typical autonumber field with a primary key works wonders for accessing database records with numerical primary keys, but it does nothing for the search engines or your search engine rankings. In walks the mod rewrites.
I talk to web designers who still have no idea what this method is, but learning how to master it will do wonders for your search engine rankings, because you can add all sorts of relevant keywords to your URLs and have spiders index them. Of course, for regular search engine optimization, you can use meta tags, ALT tags, HTML titles, and <H1> to H6 tags with keywords, but don’t forget about your URL.
Using mod rewrites, you can instruct the web server to use a “fake” or rewritten URL to substitute for the real URL:
For example:
Real URL: http://store.hotwebideas.com/?id=342 can be rewritten as http://store.hotwebideas.com/articles/modrewrites
What do you think a search engine likes better?
To do this using PHP, you need to modify or start a new.HTACCESS file on your web server’s root directory. A good knowledge of regular expressions is essential for your success at this as well.
In the .HTACCESS file, try something like this:
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^articles/(.*)/(.*) /articles.php?id=$1&c=$2
Save your file. This says that any URL with articles/(.*)/(.*) will be rewritten as articles.php?id=$1&c=$2.
So, for example, a URL of articles/webdesign/html
will be rewritten as articles.php?id=302&c=23
From here, you will need to do interpret the $_GET variables as normal.
The ^articles/(.*)/(.*) is broken down to ^ meaning the beginning of the string in PHP (and other languages) regular expressions. The (.*) means as many random characters as possible in the regular express language. It does get more complicated than that, but this is all you need to learn to get good results.
You can throw as many keywords as you want into the URL in order for this work.
Try it! You’ll like it. Let me know if you have successfully done mod-rewrites. Post some comments with examples of your web site here. I am looking forward to your mod rewrites.
