Reputation: 11111
I have this url:
http://www.site.com/products-book_1.aspx?promo=free
Here is what I have in my web.config for the UrlRewriter rules:
<rewrite url="~/products-(.+)_(\d+).aspx" to="~/product.aspx?pid=$2" />
What can I add to this expression to also retrieve the promo value? The end result would be http://www.site.com/products.aspx?pid=1&promo=free
Or do I need to think about this a different way. Every example I see just uses expression for the values before the extension, not after. What about querystrings that need to be attached sometimes?
Upvotes: 0
Views: 377
Reputation: 6808
<rewrite url="~/products-(.+)_(\d+).aspx?promo=(.*)" to="~/product.aspx?pid=$2&promo=$3" />
Actually this isn't really a good regex unless your URL will only contain the GET parameter 'promo' and none other.
EDIT
This might be slightly better: will only include promo parameter if it exists, else promo is left blank.
<rewrite url="~/products-(?:.+?)_(\d+).aspx(?:\?promo=(.*))*" to="~/product.aspx?pid=$1&promo=$2" />
Upvotes: 1