URI Transformer

“Make your links better”

News

Typo3 extension CoolURI using this URI transformer as core has come to its version 1.0.2. More

What does it do

Rewriting URIs has always been a pain in one's ass when using mod_rewrite. Not only its rules are voodoo, you have to put nice URIs into your source codes. But what if you decide to change them? Well, with URI Transformer you don't need to worry about such things. It can generate nice URIs from your source codes, where you can still use your ugly integer parameters and you don't need to bother about retrieving parameters from URIs as it's done automatically.

How does it work

First of all you need to create configuration XML. It sounds hard, but in fact it is not. With a help from the manual you can download here, everyone should be able to make it.

Then you need redirect all URIs to a central controller. You can use simple mod rewrite rules, 404 page redirection or any other means available.

Afterwards, you need to put a few lines into your controller: require_once 'link.Main.php'; $lm = new Link_Translate(); $lm->cool2params(); and decide what way you will make links in your source codes be processed by the transfomer. There are a few ways:

Example

Let's say we have a database structure which contains pages of our website. The structure looks like a tree. All subpages has its parents. The structure could look like (id, parent_id, title).

Now we would like to produce links like /page/subpage/subsubpage/. That is quite easy with URI transformer.

With a proper configuration I can call function params2cool and pass it an array with one item: $lt = Link_Translate::getInstance(); // some code echo '<a href="'.$lt->params2cool(Array('id'=>10)).'"> Some link</a>'; now the result could be <a href="/page/subpage/subsubpage/">Some link</a> As mentioned above, this is not the only way how to create a link.

Now the other way round: when a request for page /page/subpage/subsubpage/ comes the function cool2params needs to be called. Therefore put to the beginning of the controller code require_once 'link.Main.php'; $lt = Link_Translate::getInstance(); $lm->cool2params(); after that, any array (such as $_REQUEST or $_GET) will be filled with original parameters. In our case, after calling the function cool2params, $_REQUEST['id'] == 10.

Easy, right?

Where can I see it working

There's the Typo3 extension, which runs on many sites and it uses the URI Transformer as a core for transforming links.

The only site which uses URI Transfomer so far is euroinzerce.cz