Hey guys. Here is what I am trying to accomplish. I have a fully database driven site written in .NET (ASP.NET front end, VB.NET backend). Because this client is very concerned about search engine optimization and visibility, I need to keep the URLs clean within the website, and make them product-centric.
In a nutshell, the average URL in the site looks like this:
http://myurl.com/products.aspx?cid=1&sid=1Broken down, this means that the site will fetch main category 1 of products (cid) and subcategory 1 of products (sid). There are different levels of this and it goes into a bit more detail, but this is a good enough example for what I am trying to accomplish here.
Now if main product category 1 is listed by name in the database as Metal Widgets, and sub category 1 is listed by name as Blue Metal Widgets, for example, I want to rewrite the URL so it looks to the user (and more importantly the search engines) like:
http://myurl.com/metal-widgets/blue-metal-widgetsI need to basically make it verbal, and remove any .aspx filenames and replace the numeric id structure with its named counterpart.
I started doing some research on this, and started modifying the global.asax file to handle requests, but I am getting stuck. Can someone help me?
Pasted below is the function I started writing in the global.asax file (the commented out parts are pieces I couldnt figure out how to implement, that I copied from an example I found on the web):
protected void Application_BeginRequest(O
bject sender, EventArgs e)
{
HttpContext incoming = HttpContext.Current;
string oldpath = incoming.Request.Path.ToLo
wer();
string pageid; // page id requested
// Regex regex1 = new Regex(@"page(\d+).aspx", RegexOptions.IgnoreCase | RegexOptions.IgnorePattern
Whitespace
);
//MatchCollection matches1 = regex1.Matches(oldpath);
// if (matches1.Count > 0)
// {
// It's a page view request.
// Extract the page id and display the proper page.
// pageid = matches1[0].Groups[1].ToSt
ring();
// We have the pageid. Now secretly redirect the request to the actual page.
// The original URL in the web browser remains the same, but the content comes from the new URL.
// incoming.RewritePath("prod
ucts.aspx?
cid=" + pageid);
//}
}
Start Free Trial