ASP SEO friendly URLs

Posted last year, mid-September by Dave.
Categories: SEO, ASP, VBScript, Snippets.
Post Views: 1,250 Views.

One of the down sides to ASP is not being able to make SEO friendly URLs with out the need for server components. PHP can do with use of the .htaccess file. When ASP was first thought up by Microsoft the need for SEO friendly URLs wasn’t high on the list of needs. SEO wasn’t what it is today, a key to making a site successful. With the introduction of the .NET platform saw the end of development on the ASP platform. Which left web developers in a tight spot, either they install a server component (example: custom or pre built ISAPI filters) or they had to find creative ways to get around this issue.

And the answer to this is very simple. But you will need access to custom error pages. Most of all the 404 page. Copy the current 404 page into your root directory or where ever you wish and rename it 404message.html. Now create a new 404 page called 404.asp. Set your 404 error page to the 404.asp file and in this 404.asp file copy the following code into it.

Code (asp)
  1.  
  2.         Dim strQuerystring, aParameters
  3.         strQuerystring = Mid(Request.ServerVariables("QUERY_STRING"),12)
  4.         aParameters = Split(strQuerystring,"/")
  5.        
  6.         On Error Resume Next
  7.        
  8.         Server.Transfer(aParameters(1) & ".asp")
  9.        
  10.         If Err Then
  11.                 Response.Status = "404 Not Found"
  12.                 Server.Transfer("404message.html")
  13.         End If
  14.  

If you have a file called contact.asp, you would normally type www.yourdomain.com/contact.asp. With this you now call www.yourdomain.com/contact/ and what happens is the server throws a 404 error and the 404.asp gets called. The 404.asp looks at the string sent to it which looks like 404;http://www.yourdomain.com/contact/. Now the code will turn the sting into an array to grab the file name. But first it needs to move in 12 chars from the left to avoid the 404;http:// because we are splitting using forward slash and the first 2 forward slashes will cause errors.

Since we have now broken the sting into an array we look at aParameters(0) and add “.asp” to it and using Server.Transfer() we transfer to contact.asp. And the user gets the contact.asp page. The last part of the script catches errors caused by the Server.Transer(), the only error that will be thrown is if there really is a 404. And as you can see if there is an error set the Response.Status and redirect to our 404message.html

The file name with out the .asp should always be the aParameters(0), but you can have any number of pieces of information after it and the user and search bots will all see it as a folder structure. Below is a function for use of pages to read all other parts of the array. What it does is read from right to left. Example, if you had www.yourdomain.com/store/laptops/sony/ to get the sony part you would call GetRequest(1) for the laptops part call GetRequest(2). It also has an Internet Explorer fix. Internet explorer removes the last forward slash in your history. The function will check to see if the last char is a forward slash and if not adds it.

Code (asp)
  1.  
  2. Function GetRequest(id)
  3.                 strQuery = Mid(Request.ServerVariables("QUERY_STRING"),12)
  4.                 If Right(strQuery, 1) <> "/" Then
  5.                         strQuery = strQuery & "/"
  6.                 End If
  7.                
  8.                 aPara = Split(strQuery,"/")
  9.                 aCount = Ubound(aPara)
  10.                 If aCount < id Then
  11.                         Exit Function
  12.                 Else
  13.                         id = aCount - id
  14.                         GetRequest = aPara(id)
  15.                 End If
  16.         End Function
  17.  

So as you can see getting SEO friendly URLs with ASP is simple enough. For more information about search engine optimization for web sites please visit, Ireland SEO Marketing


Last 5 posts in SEO

Share and Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
    del.icio.usDe.lirio.usdiggFurlRedditYahooMyWeb

2 comments. Print Print Email Email Download a PDF version of this post. PDF
, , , , , , , , , ,  

xteb INDIA

Comment on November 27th, 2007 .

Hi, thanks for this tips.. how about the url structure I am using right now? Please give some advice if I should change it. I use /%category%/%postname%.html

It forms a url like this: http://xteb.net/seotips/wordpress-seo-strategies.html

Hope to hear back from you :)
John

Dave IRELAND

Comment on November 28th, 2007 .

John, Thats an okay structure. Except you cant use .html with the above script. I would myself go with something like http://xteb.net/seo/tips/wordpress-seo-strategies/

Leave a comment

Comments can contain some xhtml. Names and emails are required (emails aren't displayed), url's are optional.




Note: This post is over 9 months old. You may want to check later in this blog to see if there is new information relevant to your comment.

It took a bunch of illegal immigrants locked in a basement, 0.653 seconds to make this page.