regexiisurl-rewritingiis-6helicontech

Url rewriting - Querystring parsing


I am new to URL rewriting and getting a bit frustrated. I'm using Helicon on the server and have gotten most URLs to re-write correctly.

(I had to remove the '//'s to allow me to submit the questions, but the urls are the standard http:// version)

My last task is to get these:

http://example.com/Object/?page=1

http://example.com/Object/?page=1&pagesize=10

http://example.com/Object/?page=1&pagesize=10&backcolor=red

to

http://example.com/default.aspx?resource=Object&page=1

http://example.com/default.aspx?resource=Object&page=1&pagesize=10

http://example.com/default.aspx?resource=Object&page=1&pagesize=10@backcolor=red

Preferably I'd like one rule to handle all 3 possibilities, but if I need to make 3 rules, one for each, and add a [L] or something at the end that would be ok too. I just can't get the querystring parsing right.

Here is an existing rule I have that works to give you an idea of what I've been doing:

RewriteRule ^/([a-zA-Z0-9]+)(/([a-zA-Z0-9]+)(/([a-zA-Z0-9]+))?)?/?($|\?) /default.aspx?resource=$1&id=$3&option=$5 [L]

It's for a separate example, but the syntax shows what I'm doing.


Solution

  • Does this work for you?

    RewriteRule ^\/([^/]*)\/\?(.*)$ /default.aspx?resource=$1&$2 [L]
    

    [Update]

    Try this:

    RewriteRule ^([^/]*(?=\/)|[^?]*(?=\?)|.*)($|[^\?]*\?(.*)) /default.aspx?resource=$1&$3 [L]