Hmm... looks like I just need to take this one step further... I simplified the problem to make it easier to get a solution on here, but it is slightly more complex!
Because we are using URL rewriting, we are actually using the regular expression to replace the existing URL with the new one. I have modified the regular expression you gave me accordingly and for "normal" URLs, it works fine. The problem is when you get querystrings involved...
Our aim is to convert the string:
/mypage.aspx?param1=value1¶m2=value2
to:
/default.aspx?pagename=mypage¶m1=value1¶m2=value2
I.e. whatever page we come in on actually redirects to default.aspx followed by ?pagename= followed by the page name, followed by the original querystring.
The current regular expression I have, based on what I've been given on here, is:
^(/)(((?!\1).)*)(.aspx)(^.*)*.
which is replaced by
/default.aspx?pagename=$2&$3
This is almost correct, but unfortunately it seems the last letter in the pagename is finding its way into $3, e.g.
/mypage.aspx?param1=value1¶m2=value2
goes to
/default.aspx?pagename=mypage&eparam1=value1¶m2=value2
Any help again much appreciated, as I'm almost there now!
Laura