views:

33

answers:

1

I just started using URLRewriter.net with my blog and I have a problem with getting the query string values. I have a rule setting like:

<rewrite url="~/blog.aspx(\?.+)?$"
    to="~/hiddenFolder/blog.aspx?mode=default&amp;$2"/>

But when I try to access /blog.aspx?page=1 the page parameter is not passed. Other parameters work great and there are no conflicts in rewriting rules.

+1  A: 

I think the problem is that $2 is out of range as you only have one group in your RegEx. Try $1.

EDIT

In addition, it could be that the query string is being appended with another '?' so you need to move that out of the brackets.

You'll also need an extra group to make the rule match with our without the '?'. Note: we're back to $2 in the result now :)

<rewrite url="~/blog.aspx(\?(.+)?)?$"
    to="~/hiddenFolder/blog.aspx?mode=default&amp;$2"/>
TimS
I already tried with $1 or only (\?.+)? but doesn't work as suggested here: http://urlrewriter.net/index.php/support/using
HasanGursoy
@TimS: I've tried with \?(.+)?$, it works but this time blog.aspx does not work without ?
HasanGursoy
I really must learn this god damn regex :D. Thank you.
HasanGursoy
Yeah, I was saying the same thing only a few months ago. Really easy once you get started. Start with a cheat sheet http://www.addedbytes.com/cheat-sheets/regular-expressions-cheat-sheet/ and a tester: http://regextester.com/
TimS