Good-Articles.com
Search:

Home | Internet Business | Seo


Search Engine Friendly URLs for SEO

By: Venturi

Tidy up your URL by using mod_rewrite. Not only will this hide the query string, but it will make the URL look more presentable.
Friendly URL's are a very important thing to have when developing a dynamic content site that uses long query strings. A query string is something similar to a URL like you'll see on Ebay, Google and other big sites. If you're running a small to medium size website and you want to make your URL's a little easier to find you can do so via Apache's mod_rewrite by following this tutorial.
Prerequisites
You'll need to have Apache's mod_rewrite compiled into your Apache Web Server and you'll need to have access to setting some options up in your httpd.conf or at least have a server admin who's willing to do it for you. You can follow my tutorial for installing Apache web server on Linux here. For quick reference, the configure options for mod_rewrite are:

./configure

--enable-module=rewrite

--enable-shared=rewrite


I strongly urge you to carefully consider what other options you need to compile into your Apache installation. The above example is only for this one module.
Once you've compiled Apache to use mod_rewrite, you will need to setup the httpd.conf file. Here's how I set mine up for this particular situtation.
<Directory
/www/htdocs/yoursite>

Options ExecCGI FollowSymLinks Includes MultiViews

</Directory>
Some of the above directory options may not be necessary for what you are trying to do. You'll have to decide if you need them. If you are having problems you can also try to use AllowOverride All to see if you can get it to work.
Planning
It's a very important idea that you plan how to rewrite you URL's because you don't want to go back and change the links over and over again. Once you've got a good steady map of how to rewrite your links, you can go ahead and modify a test script to see if everything worked. If your links work properly then you'll be able to move on and modify all existing links. Let's take a look at this example ( http://www.good-articles.com
) :
Query String URL: http://www.good-articles.com/Article.php?id=1&name=Why-it-makes-sense-to-rent-a-car-with-driver-in-Beijing
mod_rewrite URL: http://www.good-articles.com/Article/Why-it-makes-sense-to-rent-a-car-with-driver-in-Beijing/1
Doesn't that look much friendlier?
Once you've compiled Apache, edited the httpd.conf file and planned your URL
rewriting, you're ready to setup your .htaccess file which maps out what to do with each URL. Here's an example of what to put in your .htaccess file. I'll explain how this works below.
RewriteEngine On
RewriteRule ^/(.*)/(.*)
/Article.php?id=$2&name=$1
In the example above we have two lines. The first line RewriteEngine On starts the mod_rewrite engine. The second line is what does all the work.
RewriteRule
^/(.*)/(.*) /Article.php?id=$2&name=$1
Here you are starting a RewriteRule
RewriteRule ^/(.*)/(.*)
/Article.php?id=$2&name=$1
This is the start of a regex that allows you to create wildcards for the URL that your friendly URL. This allows us to use whatever we want between the (.*) and compare them to the second part of this rewrite rule.
RewriteRule ^/(.*)/(.*) /Article.php?id=$2&name=$1
This is the final part of the rewrite rule that tells us how to map the friendly url in part 2 of the RewriteRule to the actual URL that our script was written for. mod_rewrite will translate part one to part 2 automatically.
This works by using regex. The first (.*) will be $1 and the second (.*) becomes $2 in the translation. You can do this as many times as you want for your URL.
Say for example we had this url: /name/id
We'll be matching up
/Article.php?id=1&name=Why-it-makes-sense-to-rent-a-car-with-driver-in-Beijing by using mod_rewrite!
Believe it or not that's all that's really to mod_rewriting!
You can really get carried away with this by adding category titles to some of your rewrite URLs to make them even more search engine friendly. All you have to do is create another regex and don't use that variable in your translation.
Rewriting your URLs can be valuable. We took the time to do that for most of our URLs on this website and it makes things simpler for your visitors. I encourage you to try this out and see if you like the results. Also I would like to add that you can do this by exploding your URL's in php and you would not need Apache's mod_rewrite. A tutorial will come for this someday, but for now you can get started using this "Voodoo" tool for Apache Web Server.

Article Source: http://Good-Articles.com/

This article was written by Venturi Wang, For more infomation of SEO, Vist: www.SEOBBS.Net

Please Rate this Article

 

Not yet Rated

Click the XML Icon Above to Receive SEO Articles Via RSS!

Copyright © 2006-2008 Good-Articles.com All Rights Reserved.
Use of our service is protected by our Privacy Policy and Terms of Service

Powered by Article Dashboard