PostNuke: A Flexible Open Source Content Management System
home | forum | international support | contact us

News

documentation PN 0.8 is full of good surprises, especially in the case of the URL rewriting which has been entirely reworked. Thus PostNuke offers several methods in order to help us to make urls more attractives.


Main principles of the mod rewrite

For information, the URL rewriting is a module that you can activated in your apache to rewrite the links of a site in order to simplify their reading. The idea is that the PN Team also thought that the mod rewrite was not necessarily available / activated on all types of servers (particularly on Windows servers). Indeed, the PostNuke team offers rewritings based on tips already heavily used in management systems like blogs. Before you begin, here is the format of a link without rewriting.

without rewriting index.php?module=Users&func=logout Index.php? Users & module = func = logout

URL rewriting without mod rewrite

This rewriting reproduced a "virtual" Folders system on your site, links look like this
URL rewriting without mod rewrite index.php/Users/logout

In terms of mechanism, it is very simple, when your Web server receives a request for a link, it loads instinctively page "index.php". In this index.php, the parameters of the request are recovered via the header (you can look in "phpinfo" there is a field $ _SERVER [ 'REQUEST_URI'] which corresponds to this information).Then these parameters are interpreted , between the first two "/" is the name of the module, between the two others, the function name. Now PostNuke know the name of the module and function to launch.

You can pass parameters too, for instance, if you want to load a forum with id=2, the links will look like this

URL rewriting without mod rewrite index.php/Forum/viewforum/forum:2

Note that the URL rewriting uses ":" to represent the parameters in a URL. So you can't pass variables like this "index.php?variable=filter:3". (be carefull if you are using Pagesetter and his filters system).

URL rewriting with mod rewrite

Optimizing the previous version

In the previous example, all links contained index.php ... but it's ugly, and functionally this file contains no information useful to load the asked module.This trick is useful when you have no mod rewrite, but if one has an "mod rewrite enabled" server,you can use a "lighter" version of the previous rewriting without an "index.php"

Here is an example

URL rewriting with mod rewrite :Optimizing the previous version /Users/logout

Be careful, if one of your pictures is written this way <img src="test.png"> and you load the page /MyModule/main/. "/MyModule/main/test.png" which will be searched. Note that you can make a rewriting that redirect all links of the form "/*/*/*.(jpg | png | gif)" to "$ 3. (Jpg | png | gif)." (but it's ugly).

Mode file

This URL rewriting is the classical version already used in previous versions of the CMS, The rewrited links are lists of words (module name, the name of function) separated by dashes. Note that this version uses a large number of regular expressions rules to do the rewriting compared to the other one, which may increase the load of your server Web.

One example here ...

URL rewriting with mod rewrite : Mode file module-Forum-viewtopic-topic-2903-start-0.html

Note that the "module" which one would have thought there's no point in it, is made for the support of the "old style" loading of modules.

URL rewriting customized

So here is the coolest feature, which allows you to customize the URL rewriting depending on the module you want to load. Just create a "encodeurl" function in your API module (pnuserapi) that takes as parameters, the information needed to create for output a fully customized rewrited link.

After, the loading of each page of the CMS, a "decodeurl" function in the API part of the module takes care to reformat the encoded URL in a form understandable by the CMS.

You can find an example of the use of this method in the module "Pages" of values addons

Format of a encode and decode URL function pages_userapi_encodeurl($args) function pages_userapi_decodeurl($args)

This feature is interesting because it allows us to have the hands on your URL, not only before loading the page, but after loading this page, allowing you post-processing actions rather interessant.

This method allow you to

  • - put keywords in the URL: (see Pages module)
  • - have a single version of your rewrited URL : Indeed, through the post treatment you can recalculate the URL and it does not conform to your requirements, you can redirect to the good link via a redirect 301 "Moved Permanently headers.
Use case of a URL rewriting "no duplicate"
Notes: A small problem nevertheless for the use of this rewriting, which is limited to the type URL "user". (more details here) This article is a translation from this "how to" released on Postnuke-France
 
Posted by mumuri  on Monday, February 25, 2008 Comments (5) · 1476 Reads

5 Comments so far

(Latest comments )

kaffeeringe.de's Avatar

1. kaffeeringe.de wrote on Feb 25, 2008 at 03:11 PM

WOW! icon_eek What a great article! n1ce!
AmmoDump's Avatar

2. AmmoDump wrote on Feb 25, 2008 at 04:12 PM

Great reading!

mumuri's Avatar

3. mumuri wrote on Feb 26, 2008 at 09:29 AM

thanks

i forget to give this other link

For information, the source of this new rewriting ?

http://community.postnuke.com/Article2703.htm

nestormateo's Avatar

4. nestormateo wrote on Feb 26, 2008 at 04:17 PM

Very nice article mumuru! Thank you!
Just a little update: it seems that now the "Directory mode" parameters are not separated with ":" anymore, now the URL looks like:
/Forum/viewforum/forum/2
/Downloads/view/cid/1

I'll customize a lot of URLs icon_smile
Thanks again!
mumuri's Avatar

5. mumuri wrote on Apr 03, 2008 at 10:18 PM

default module take of patch icon_smile
http://noc.postnuke.com/tracker/index.php?func=detail&aid=15606&group_id=5&atid=103

Main Menu

Extensions Database

Documentation

Development

Login





 


 Log in Problems?
 New User? Sign Up!

Donate to PostNuke