CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Grant Killian's Blog

No, this has nothing to do with beer -- but maybe it should?

SEO, .Net, and URL Rewriting

Although preliminary findings by Scott Mitchell indicate blog posts on Fridays aren't paid much attention, I'm going forward with a Friday afternoon blog entry.  What the heck, the office is practically empty and I'm all caught up for once.

Something that has been coming up more and more is SEO, or Search Engine Optimization.  It's a big deal for our ecommerce customers who want to be high in the Google and Yahoo search results.  While I don't get involved in the SEO details very often, there are ways that software development (which is my main job) overlaps with SEO.  One of these main overlaps is with URL Rewriting -- where you map a search engine unfriendly name like “http://www.Domain.Com/products/prodDetailView.aspx?pid=3432&catid=3434355” to something more meaningful to the search engine spiders like “http://www.Domain.Com/TabletPC-Computers.aspx”.

I don't know the ins-and-outs of google's algorithm (although in a few conversations with these guys they claim to), but the full substance of an HTML page can be considered by the search engines. This means the first url with the nasty querystring is meaningless and can't contribute to a page's search ranking, while the 2nd url is more substantial and may add to the page's rank for TabletPCs and Computers.

Before .Net this was a tricky ISAPI issue for Windows servers; now, via the HttpContext.Current.RewritePath() method, we can Rewrite URLs relatively easily.

This CSharpFriends article has a quick snippet that illustrates the basics; 15Seconds has a much more in depth treatment.  We've got our own “engine“ and the boss man would frown on me posting it (although it's not rocket science!).  You intercept the request for the friendly URL in the Application_BeginRequest event handler and rewrite it as the one your system recognizes:

   HttpContext myContext =  HttpContext.Current;
   myContext.RewritePath("HttpContext_Next.aspx");

To understand the SEO side a bit more, check out Page 1 or Page 2 of this article from the SEOConsultants. 

In the future I may discuss some of the other ways software development supports a site's SEO efforts; after all, who cares if the site is well programmed if nobody can ever get to it?

Happy .Netting!



Comments

Darrell said:

Do you use a database or config file to link the unfriendly URL to the friendly URL? Or is it hard-coded?
# April 3, 2004 6:42 AM

Grant said:

A database with a user-administered interface.
# April 3, 2004 10:44 AM

sandeep pandit said:

hello sir,
i read your article on URL rewriting in asp.net on msdn.i have also used the same in my

project.URL rewriting is working fine in our LAN and on our configured IP but problem is

that when we host our site to some ISP its not working and giving error like this "THE PAGE

CAN NOT BE FOUND" its really emberrasing because i am not able to find out the proble any

where
i am seding the code which i am using
Sample code
==================
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
' Fires at the beginning of each request
Dim context As HttpContext
context = HttpContext.Current()
Dim strOldPath As String
strOldPath = Trim(context.Request.Path.ToLower())
Dim strToken As String
strToken = "accomodationdetail"
Dim intI As Integer
intI = strOldPath.IndexOf(strToken)
Dim intLen As Integer
intLen = strToken.Length
Dim intJ As Integer
If intI <> -1 Then
intJ = strOldPath.IndexOf(".aspx")
If intJ <> -1 Then
Dim strDetail As String
strDetail = strOldPath.Substring(intI + intLen, intJ - (intI + intLen))
Dim strNewPath As String
strNewPath = strOldPath.Replace(strToken + strDetail + ".aspx",

"AccomodationDetail.aspx?intID=" & strDetail)
context.RewritePath(strNewPath)
End If
End If
end sub
============================

but when i called some page like this

original request=/accomodation/accomodationdetail22.aspx
after rewrite=/accomodation/accomodationdetail.aspx?id=22
above request is doing fine in our lan and on our configured IP
but not working on ISP where we host our site
and giving error "THE PAGE CAN NOT BE FOUND"
i think you got my problem
please help me as soon as possible
thanks
regards
sandeep
MY MAIL id IS spandit@rsbsystems.com
# April 27, 2004 11:43 PM

Dennis said:

Sandeep,
You probably have a solution by now but the problem can be fixed by copying the global.asax file to you application folder.
# July 16, 2005 12:35 PM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add
Check out Devlicio.us!