Clean URL

Some people don’t like URLs like “”. They rather prefer URLs like ““. Since CMSimple produces the first type of URL, we have to change something, that CMSimple produces the second type. And this is not so easy.

First of all, the method described here requires Unix/Linux servers. It wont work on windows servers. A next prerequisite is the mod_rewrite package which has to be loaded on your server and configured correctly by your ISP.

The method is a compilation and correction of a thread in CMSimple's Forum. It follows seven steps and has been tested on two different Linux servers with PHP5 one of which was a free FunPic server. The test environment was CMSimple v2.9 (this is important, since the line declarations in “Method” may vary in the different versions).


Edit the file cmsimple/cms.php. Add


on line 88 just above the line which says: // define su - selected url.

Search for and replace function a() with

function a($i,$x) {
	global $sn,$u,$cf;
	return '<a href="'.$sn.($cf['urlrewrite']['base']?'':'?').$u[$i].$x.($cf['urlrewrite']['base']?'.html':'').'">';

You will find it around line 316 of cms.php.

Edit the file cmsimple/config.php. Add at its very end the variable:


Add it just above the ?> sign. This works only if CMSimple is running in the root of your site. It CMSimple is running in a subdirectory you have to say



Now CMSimple produces URLs which look like It wont work, though, since the server still expects /?1_level_page. We have to tell him to understand both. To do this we activate mod_rewrite. And we do it with a .htaccess Linux configuration file.

On your workstation generate a file called htaccess.txt. (Windows does not allow to generate a file called .htaccess.) fill this file with:

RewriteEngine on
# To prevent loop:
RewriteCond %{REQUEST_URI}  !index.php
# Do not rewrite requests to template or images dir:
RewriteCond %{REQUEST_URI}  !templates
RewriteCond %{REQUEST_URI}  !images
# Do not rewrite requests with any query strings:
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)\.html$ /index.php?$1

Save it and load it on your server into the root or there where CMSimple‘s index.php file resides. Rename the file to .htaccess. (Do not forget the dot in front of name. It wont work without it.) In order to see this file now, your FTP client has to be configured to make hidden files visible.

Now it should already work! You will be able to work with URLs like However second or third level pages will still turn up URLs like If you can live with this you should stop here. However, if you edit cmsimple/config.php and change $cf[’uri’][’seperator’]=”:”; to $cf[’uri’][’seperator’]=”/”; (colon to slash), you will have slashes and no colons anymore. But your site is unable to find the stylesheet. The reason: a third level page has to look back for its stylesheet at ../../templates/your_template/stylesheet.css, where it usually does not look. It looks at ./templates/your_template/stylesheet.css. To correct this we have to change the head() function in cms.php. But please, be warned and test your website carefully, afterwards! It is possible that plugins or scripting may not work correctly anymore - especially if it is delt with paths. In this test, a switch_template_on_the_fly script was not performed correctly.

Edit cmsimple/cms.php and add to line 80 the code:

$pth['uri']['stylesheet']=$cf['urlrewrite']['base'] . $pth['file']['stylesheet'];

It has to be placed below all the declaration of variables. Or it wont work.

Search for and replace function head() with:

function head() {
	global $title,$cf,$pth,$tx,$hjs;
	if($cf['site']['title']!='')$t=$cf['site']['title'].' - '.$title;
	else $t=$title;
	foreach($cf['meta'] as $i=>$k)$t.=meta($i);
	if($tx['meta']['codepage']!='')$t.=tag('meta http-equiv="content-type" content="text/html;charset='.$tx['meta']['codepage'].'"');
	return $t.tag('meta name="generator" content="CMSimple 2.9 -"').tag('link rel="stylesheet" href="'.$pth['uri']['stylesheet'].'" type="text/css"').$hjs;

You will find the function around line 390.

Edit cmsimple/config.php and exchange




Colon to slash.

And you are done.

Important Note at the End

This will not work, if you are using special characters like german umlaute and stuff in your headings. The servers are not able to deal with something like äöüß.html.

tips_and_tricks/clean_url.txt · Last modified: 2008/06/04 10:57 by till