View Single Post
Old 02-05-2006, 06:03 AM   #4
Laurens
Jah Blessed
Laurens is no ebook tyro.Laurens is no ebook tyro.Laurens is no ebook tyro.Laurens is no ebook tyro.Laurens is no ebook tyro.Laurens is no ebook tyro.Laurens is no ebook tyro.Laurens is no ebook tyro.Laurens is no ebook tyro.Laurens is no ebook tyro.
 
Laurens's Avatar
 
Posts: 1,295
Karma: 1373
Join Date: Apr 2003
Location: The Netherlands
Device: iPod Touch
Smile Link Rewriting In a NutShell (TM)

The key to link rewriting is using so-called "marked subexpressions".

The regular expression for matching article URLs is fairly straightforward:

http://.*\.?opendemocracy\.net/.*/article\.jsp\?id=\d*.*articleId=\d*.*

What you want to do is extract certains parts of a matching URL to construct a handheld-friendly URL. You can do this by marking these parts as subexpressions by putting them between parentheses:

(http://.*\.?opendemocracy\.net)/.*/article\.jsp\?id=(\d*).*articleId=(\d*).*

Each subexpression in a matching link is assigned a number. You have to put a dollar sign in front of them when rewriting the link. In this case there are three submatches: $1, $2 and $3.

Once you have understand this and have this working, rewriting the link becomes very simple:

$1/articles/ViewPopUpArticle.jsp?id=$2&articleId=$3

There's far more to regexp, but you don't need to know everything to use link rewriting.
Laurens is offline