views:

34

answers:

1

Can anybody help me regarding URL rewriting. As I have the URLs like

http://somedomain.com/products.aspx?id=1

and i want to rewrite this like

somedomain.com/productname

and rest of the URLs on the domain work as they are provided. like

somedomain.com/forums/categories.aspx

I don't want to rewrite these other URLs

Regards, John

A: 

do like this in ur global.ascx file

from where u r redirecting on this, there page u can do like this there

response.redirect("somedomain.com/productname");

void Application_BeginRequest(object sender, EventArgs e) { string fullOrigionalpath = Request.Url.ToString();

    string[] words = fullOrigionalpath.Split('/');
    string d = words[words.Length-1].ToString();
    if (!d.EndsWith("aspx"))
    {
        Context.RewritePath("/products.aspx?id=1);
    }

}
developer8
its not just the products page,as there are other pages too, that may be rewritten later.So, thats why i want to handle this through the regular expressions.<rule> <url>/URLRewriterM/s/h/o/w/(.*)\.html</url> <rewrite>/URLRewriterM/show.aspx?id=$1</rewrite> </rule>