Converting dynamic URLs to static
Posted on August 3rd, 2008 | by ronaldborla |Dynamic URLs are those addresses of your dynamic website with these symbols: “?&=“. These are often called as “query strings” and it help optimize your webpages to be as dynamic as possible. Though it offers a great advantage for your website, it comes up with a corresponding disadvantage: most search engines and Google hate dynamic URLs, so it won’t be indexed as effective as static URLs. Simply speaking, dynamic URLs aren’t SEO friendly unlike those static ones. In this article, I’ll be discussing a little bit of information on how to convert the dynamic URLs to static of your website running under Apache 2.0 or higher.
The first thing you have to consider is whether your Apache is running the “mod_rewrite” module. You can check this by opening your PHPInfo(). Under apache2handler section, loaded modules, if you can see the “mod_rewrite” then your fine to go, otherwise, you have to enable this first by modifying your “httpd.conf” file. Search for “LoadModule rewrite_module modules/mod_rewrite.so” then remove the “#” symbol within this line. Restart your Apache, then check if it has already been loaded.
The mod_rewrite module works by converting static URL requests to the dynamic URL recognized by your PHP pages before the server processes the source codes. Thus, though the clients are requesting for the static URL, the mod_rewrite function provides the corresponding dynamic URL but still, showing the actual static URL request. Through this, when search engines try to crawl on your website, the configured static URLs will be provided rather than their corresponding dynamic URLs.
To configure the static URLs allowed along with the corresponding dynamic URLs, create or modify the “.htaccess” file in your website’s root directory, then add the following codes:
Options +FollowSymLinks
RewriteEngine on
RewriteRule [static URL, (.*), (.*), (.*),...] [dynamic URL, $1, $2, $3,...]
RewriteRule function has the paramaters as shown above. First parameter is the static URL to convert. Second parameter is the corresponding dynamic URL. As you notice above, there is “(.*)” in the first parameter, while there are “$1, $2, $3″ for the next paramater. The $1, $2, $3,… represents the dynamic value of the query string variables per dynamic URL. For instance, we have a URL http://ronaldborla.info/index.php?variable1=value1&variable2=value2&variable3=value3. Noticeably, the query string variables are “variable1, variable2, variable3″ while each’s corresponding values are “value1, value2, value3″. These are the values which $1, $2, $3 represent. Now values (.*) in the first parameter of the function are passed according to the order of instances of the $1, $2, $3 in the second parameter.
Now let’s have a better example of this: Suppose the client requests for a page in your website with the static URL http://ronaldborla.info/personal/1/. We have this code in our .htaccess:
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*)/(.*)/ index.php?category=$1&viewpost=$2
Digging in with the code of the URL, the first (.*) obviously represents the word “personal” while the second (.*) represents “1″. Right when the client requests for this static URL, the RewriteRule function will make use of the values “personal” and “1″ and will be passed to the second parameter specifically to the “$1″ and “$2″, respectively. So, virtually, the new URL which the server will be required to process is: index.php?category=personal&viewpost=1.
There is a rather much more complicated means of using this function, and it is through Regular Expressions. Anyway, the above information are just basics for mod_rewrite and ideally explains the concept of the module. The article in this link here explains some complicated uses of mod_rewrite. Finally, if you just want to have a quick conversion of dynamic URLs to static, you may use this tool provided by WebConfs.com.