I am trying to add some rewrite rules using UrlRewriter.net to my ASP.NET web app. The problem is that I am a Regex newbie, and provided examples are pretty elementary.
My question is: how do I differentiate urls which contain GET query parameters?
I.e., if I add this rule:
<rewrite url="~/([.+])" to="~/$1.aspx" />
It will rewrite www.example.com/products
to www.example.com/products.aspx
, but it will also rewrite www.example.com/products?id=1
to www.example.com/products?id=1.aspx
.
Problem actually only happens when using a login control, since it creates an url similar to www.example.com/login?returnUrl=/members
, and I am not sure how to rewrite it.
What I would like is:
- to rewrite
www.ex.com/test
towww.ex.com/test.aspx
, and - to rewrite
www.ex.com/test?page=dummy
towww.ex.com/test.aspx?page=dummy.aspx
Thanks a lot!
[edit] And btw I still haven't figured how to turn on console debugging for Url开发者_如何学运维Rewriter. I have added the "register logger" section to the config file, but VS output windows shows nothing. That would be helpful, also.
Use the following regex for the match:
"~/([^\?]+)(.*)?"
This way you match everything until the question mark - one or more chars that aren't a question mark.
Then $1 holds the path part, and $2 everything from the "?" until the end of the URL.
Notice the question mark after the second grouping parentheses - this means that you don't require that part, so www.ex.com/test
will also work.
精彩评论