posts - 81, comments - 259, trackbacks - 0

MediaWiki Short URLs with IIS 7 and Subpages

Following the guide on got me 99% there with nice short URLs on Windows with IIS 7.

One small hiccup, creating subpages of the form


The suggested Regular Expression provided by URL Rewrite needs a simple update.

<match url="^([^/]+)/?$" />

Should be

<match url="^([^/]+.+?)/*$" />

Or, as is done in the guide, with the wiki path

<match url="^(wiki/[^/]+.+?)/*$" />

Understanding the change requires reading the original regular expression.

  • "^" Match from the start of the string
  • "[^/]" Here "^" has a special meaning, it negates "/" so that this matches any character but "/"
  • "[^/]+" The plus means to match at least once or more
  • "([^/]+)" The parenthesis are simply a grouping, so that what's matched inside is the available as the 'first match'. Put another way this selects the output from the pattern match. "{R:1}" is actually this value being used.
  • "/?" Matches none to one "/" non-greedily (more on that).
  • "$" Matches the end of the string

We would like it to match a title with "/" within it. MediaWiki will handle the details of splitting the title into subpages. We are already matching anything but "/", so we might as well match anything. In RegEx, a "." means just about anything (anything but a new line). We still don't want to start a title with "/", so after the first non "/" matches, lets accept anything up until the end of the string. We do that by simply inserting ".+", matching one or more of anything but a new line.

As you might have noticed, the new patterns have two other changes, an additional "?" and replacing the last "?" with "*" at the end of the pattern. Why gets into something called greedy and non-greedy matching. Consider the following path


Where should the trailing "/" go? Should it be part of the title or matched as an optional end of the path, but not part of the title? The title should be "PageTitle/SubPageTitle" and not "PageTitle/SubPageTitle/", but the title matching, "([^/]+.+)" and the trailing "/" matching "/?" both may match the ending "/".

What we do is add a "?" just after the "+" to match non-greedily. When this is done, the pattern will match as short of a pattern as possible. But, we now need the trailing "/" to match greedily. We can do this easily by changing the "?" to "*" which will greedily matching zero or more trailing "/".

And there you have it, subpage support.

Print | posted on Tuesday, August 28, 2012 4:21 AM |



# ugg saappaat

Uggs boots keep feet toasty even in the freezing cold days and ugg saappaat therefore have become the ugg saappaat suomesta first choices of many customers xiaocaicl15. ugg saappaat boots This kind of footwear looks fashionable ugg saappaat oulu and unique and is available in different uggs saarbr├╝cken styles and colors for your choices. Made with twin-faced sheepskin, these boots feel incredible ugg boots udsalg warm and comfortable. Many celebrities are ugg boots dk also spotted wearing them during the winter season ugg boots tilbud to go through the cold winter. But this conception is ugg boots online quite wrong, as wearing them sensibly especially with jeans and feathery coats really looks cool and exquisite.
11/13/2012 3:14 AM | Zkjykgsng01

Post Comment

Please add 1 and 2 and type the answer here:

Powered by:
Powered By Subtext Powered By ASP.NET