Reputation: 6693
I'm trying to set up a url rewrite rule using Microsoft IIS URL Rewrite 2.0, I'm running IIS7 and .NET 4.
I want to match any number of a specific pattern, for example:
www.test.com/test1/
www.test.com/test1/test2/
www.test.com/test1/test2/test3/
www.test.com/test1/test2/test3/test4/ etc...
and [respectively] rewrite the results as
www.test.com/page.aspx?q=test1
www.test.com/page.aspx?q=test1&q=test2
www.test.com/page.aspx?q=test1&q=test2&q=test3
www.test.com/page.aspx?q=test1&q=test2&q=test3&q=test4 etc...
or
www.test.com/page.aspx?q=test1
www.test.com/page.aspx?q=test1,test2
www.test.com/page.aspx?q=test1,test2,test3
www.test.com/page.aspx?q=test1,test2,test3,test4
This is a fairly straight forward thing to do when using the standard c# regex engine (I have considered creating a custom HttpModule to handle this and iterating over a Match collection), however I wanted to know if it was possible to do with the IIS url rewrite component as I'm using this quite happily for other parts of the site.
Any ideas?
Upvotes: 0
Views: 183
Reputation: 455
If you're using .net 4.0, what not use Routing?
http://everymanprogrammer.com/index.php/asp-net-4-0-routing-a-simple-tutorial-that-works/
Upvotes: 0
Reputation: 190942
Why don't you just match and pass in
www.test.com/page.aspx?q=test1/test2/test3/test4
Then it would be up to page.aspx
to parse it how it needs it? That way your configuration won't have to change when it really is application logic.
Upvotes: 1