url rewriting – ASP.Net URL Rewriter – Education Career Blog

We’re using URLRewriter (http://urlrewriter.net), and would like to rewrite queries like this:

domain.com/find/red-boots

to this:
domain.com/search.aspx?k=red+boots

The sample code to go into the web.config is this (I’m a bit unfamiliar with this syntax)

<if url="/tags/(.+)" rewrite="/tagcloud.aspx?tag=$1" />

How can I code this line in the web.config to get it to rewrite the way we need? Also, if you have any good advice on how to brush up on the rewriter syntax, that would be great too.

,

The “rewriter syntax” you are asking about is called regular expressions. There are many great tools out there, just search Google for “regex help”.

However if you would like to use a syntax that has a little more history behind it, so you can get more detailed help. Please check out the Managed Fusion Url Rewriter, which uses the Apache mod_rewrite syntax, which has been the standard for more years than I can cound. Here is how you would complete your question in mod_rewrite syntax:

RewriteRule ^/find/(.*)       /search.aspx?k=$1      NC,L

The first part after the RewriteRule is the input that tries to get matched against the URL Requested by the browser. The second part is the transformation, that happens against the matched rule. The transformation turns it into something your application can understand. The last part in the brackets are control tags, in this case I am telling the RewriteRule to not worry about the case of the characters which is indicated by NC and that if matched it should treat this as the last processed rule which is indicated by L

Leave a Comment