Creating a Free and Open Source Software ecosystem to facilitate government FOSS policy implementation
by Derek Keats
Using the present to create the future: How can we move South Africa from consumer to producer of web technologies
by Derek Keats
An ecosystem approach to building mobile opportunities into a business strategy
by Derek Keats
I had an interesting conversation with Charles Majola yesterday about static urls in Chisimba. He was unable to get a client to use Chisimba because of the fact that there are only dynamic URLs available. While this is not quite true as there are at least three different URL rewriting tools in Chisimba, the automatic rewriting of URLs has never been done. Possibly there are two reasons for this:
Dynamic URLs are the kind that look like
http://localhost/ch/index.php?module=blog
&action=viewsingle&postid=gen18Srv59Nme5_2225_1316529949
&userid=1563080430.
With the Chisimba Short URL module installed, this could be
http://localhost/ch/daedalusphotos/
which is a static URL. A static URL could still represent all of the information in the original URL using a different technique, for example:
http://localhost/ch/blog/viewsingle/postid-gen18Srv59Nme5_2225_1316529949-userid-1563080430.html
which is still a mouthfull, but is a static URL.
Static URLs are generally assumed to be better than Dynamic URLs because:
However, it needs to be born in mind that static URLs add overhead to the server, and require mod_rewrite to be turned on in Apache. Also, this only works on a Linux server as far as I know. I am not entirely convinced that the gains of using them outweigh these penalties, but in the world of business perception is reality, so as Kenga takes Chisimba to market, we will need to have static URLs in our toolkit. So here I am looking at how we could implement this in Chisimba.
There are two different things that have to be accomplished in Chisimba to make static URLS:
Lets take the first one first. Chisimba URLs are generated by a method in the object class, called uri(). A disciplined developer who adheres to Chisimba coding standards will build a link by calling this method, and passing it an array of key => value pairs, as well as the module to be called. For example the link
http://localhost/ch/index.php?module=blog
&action=viewsingle&postid=gen18Srv59Nme5_2225_1316529949
&userid=1563080430
used above will be created using the uri() method as follows:
$linkUri = $this->uri(
array('action' => 'viewsingle',
'postid' => 'gen18Srv59Nme5_2225_1316529949'
'userid' => '1563080430'), 'blog');
This means that the uri() method could be used to construct the link differently based on a system parameter. For example, USE_STATIC_URLS could be set to TRUE or FALSE, FALSE by default. This would allow the uri() method to have additional code added to create either dynamic or static URLs.
The manner in which these static URLs are accomplished is going to be difficult in Chisimba because of the fact that it is not a single type of application. For example, we could use a concatenated title string for the blog, if all we were was a blog, but we cannot do that because any module can be the main module in Chisimba, and it is a multipurpose system. Here I suggest starting with pseudo directories, based on something that all modules will have, which is modulecode and action. Therefore we could have
http://localhost/ch/$modulecode/$action/
such that
http://localhost/ch/slate/view/
would open
http://localhost/ch/index.php?module=slate&action=view
The rest of the URL could then be constructed as
$param-$value~$param2-$value2~$param3-$value3.html
such that
postid=gen18Srv59Nme5_2225_1316529949&userid=1563080430
becomes
postid-gen18Srv59Nme5_2225_1316529949~userid=1563080430
There are other approaches that could work, including the one provided by http://www.webconfs.com/url-rewriting-tool.php as discussed further below.
The second thing that has to be accomplished is the parsing of the static URLs to access the dynamic content page. This requires Apache server with mod_rewrite turned on, and a .htaccess file to hold the rules for parsing the static URLs.
The difficulty with a complex application is to ensure that there is no duplication between static and dynamic URLs as this will result in a search engine penalty. Therefore, all public links in a given Chisimba installtion will have to point to the static URLs to avoid these penalties due to having duplicate URLs. We could generate a robots.txt file, and add all dynamic URLs to keep the search engines from spidering the duplicate URLs.
The URL rewriting tool at http://www.webconfs.com/url-rewriting-tool.php
takes the URL
http://localhost/ch/index.php?module=blog&action=viewsingle&postid=gen18Srv59Nme5_2225_1316529949&userid=1563080430
and provides two options
OPTION 1: Generated URL
http://localhost/ch/index-module-(Any Value)-action-(Any Value)-postid-(Any Value)-userid-(Any Value).htm
eg. http://localhost/ch/index-module-blog-action-viewsingle-postid-gen18Srv59Nme5_2225_1316529949-userid-1563080430.htm
Create a .htaccess file with the code below
The .htaccess file needs to be placed in localhost/ch
Options +FollowSymLinks
RewriteEngine on
RewriteRule index-module-(.*)-action-(.*)-postid-(.*)-userid-(.*).htm$ index.php?module=$1&action=$2&postid=$3&userid=$4
OPTION 2:
Generated URL
http://localhost/ch/index/module/(Any Value)/action/(Any Value)/postid/(Any Value)/userid/(Any Value)/
eg. http://localhost/ch/index/module/blog/action/viewsingle/postid/gen18Srv59Nme5_2225_1316529949/userid/1563080430/
Create a .htaccess file with the code below
The .htaccess file needs to be placed in localhost/ch
Options +FollowSymLinks
RewriteEngine on
RewriteRule index/module/(.*)/action/(.*)/postid/(.*)/userid/(.*)/ index.php?module=$1&action=$2&postid=$3&userid=$4
RewriteRule index/module/(.*)/action/(.*)/postid/(.*)/userid/(.*) index.php?module=$1&action=$2&postid=$3&userid=$4
Neither of these approaches will be ideal for Chisimba, but the principle is clear.
This would lead to an automated approach. We could also have module specific static URLs, but the danger of having both is that links to them will result in duplicate URLs, and search engine penalties.
I would appreciate some feedback on this, as it is something that we must implement as we take Chisimba out into the commercial world.
http://www.webconfs.com/dynamic-urls-vs-static-urls-article-3.php