ASP 101 - Active Server Pages 101 - Web03
The Place ASP Developers Go!

Please visit our partners


Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates














ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash



 Top ASP 101 Stories Top ASP 101 Stories
Getting Scripts to Run on a Schedule
The Top 10 ASP Links @ Microsoft.com
What is Adovbs.inc and Why Do I Need It?

QUICK TIP:
Make Access Write Your SQL For You
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates


Extending Your Page Names

Extending Your Page Names

by Wayne Berry

Introduction

Dynamically generated pages are the only way to have a truly big site, however dynamic page names are not very user friendly. For example, having a page called product.asp?Id=4 is not as memorable as: /applicances/dishwashers/kenmore/Model3809.htm. This article shows how you can get a static-looking page name and dynamic pages at the same time.

Search Engines

There is another benefit to having well-named pages, search engines are able to traverse these pages. Most search engines, like Alta Vista and Yahoo do not traverse pages with question marks in them, since they are afraid of entering into a never-ending traverse. By converting your dynamic page names to static pages, search engines would categorize these pages driving more traffic to your site.

Minimum Requirements

In order to get well-named pages , you will need to use Windows 2000 and IIS 5.0. There are two new enhancements in IIS 5.0 that allow you to have great pages names, Custom Error Pages that use Server.Transfer and the ability to use Server.Transfer in our Active Server Pages. Even though Custom Error Pages were available in IIS 4.0, they used Response.Redirect, which will not work, so this example requires IIS 5.0. Response.Redirect will not work because search engines do not follow redirects.

Overview

As the site programmer, you link up pages that don't exist -- presumably with well-named URLs. You then tell IIS that you want an Active Server Page (404.asp) to handle all the 404s that come to the site. Inside this Active Server Page, you convert the original URL to a well-named URLs and do a Server.Transfer to execute and return that page to the user's browser.

Getting Started

If you open a browser and type in:

http://www.myserver.com/applicances/dishwashers/kenmore/Model3809.htm

Where you fill in myserver.com with your web site name the page will return 404. The first thing that to do is to have all your 404 pages handled by a single .asp page. You can do this by using the Custom Error Page feature of IIS 5.0. To turn on custom error pages follow these steps:

  1. Open IIS Manage In MMC.
  2. Right Click on the web site node and choose properties.
  3. Click on the Custom Errors Tab.
  4. Scroll down until you see the HTTP Error -- 404.
  5. Double click on 404 to open the "Error Mapping Properties" dialog.
  6. Change the Message Type to URL.
  7. For the URL enter in /404.asp
  8. Click OK and Then OK again.

Now all your 404 errors will be handled by 404.asp. The nice thing about IIS is that when it calls 404.asp, it will send the page name that caused the error as a parameter in the querystring.

404.asp

Now create a 404.asp page to handle your errors. The first thing that you need to do is get the name of the page that had the 404. This line of code will get the page name from the query string:

<%
' Get the Page Name
strQ = Request.ServerVariables("QUERY_STRING")
%>

So what is important to use in the strQ? In the example above it appears like: /applicances/dishwashers/kenmore/Model3809.htm. All we really need from it is the Model3809, since this could be the unique key to the product database. The following lines of code takes the model number and find the product id.

<%
' Find the Model Number
nIndex = InStrRev(strQ,"/")
If (nIndex>0) Then
	strModelNumber = Right(strQ,Len(strQ)-nIndex)
	strQ = Left(strQ,nIndex-1)
End If
' Trim Off .htm From Model Number
If	((Mid(strPageName,Len(strPageName),1)="m") And _
	(Mid(strPageName,Len(strPageName)-1,1)="t") And _
	(Mid(strPageName,Len(strPageName)-2,1)="h") And _
	(Mid(strPageName,Len(strPageName)-3,1)=".")) Then
	strModelNumber =Left(strPageName,Len(strModelNumber)-4)
End If
' Look Up the Product Id In the Database
strSQL = "SELECT Product_Id FROM Product " _
	& "WHERE Product_Model = '" & strModelNumber  & "'"
Set oRS = oConn.Execute(strSQL)
If (Not oRS.EOF) Then
	lProductId = oRS("Product_Id")
End If
%>

Now that we have the Product Id we need to store it before transferring to the correct .asp page. We can't pass the Product Id in the query string via the Server.Transfer (this is an IIS restriction). So, we pass it via the Session Object.


<%
	Session("Id") = lProductId
	Server.Transfer("/product.asp")
%>

When you try this, your address bar in the browser will say:

http://www.myserver.com/applicances/dishwashers/kenmore/Model3809.htm

and because of the Server.Transfer the URL in the browser's address bar doesn't change, also the browser doesn't have to perform another round trip, unlike Response.Redirect.

Also notice that the directories do not exist at all, in fact it doesn't matter in this case what the rest of the URL says -- except the server name. For instance all these URLs go to the same page:

http://www.myserver.com/Model3809.htm
http://www.myserver.com/trucks/ford/Model3809.htm

So why put in the directories? The directories will give you higher search engine placement. Because some search engines use the words in the query string as stronger keywords to the search than words in the title or body of the HTML, directory names are very important.

Calling Pages that Don't Exist

We have covered the technology to convert URLs that don't exist to dynamic URLs, however in order to get the search engine to traverse those pages you need to link to the URLs that don't exist. In other words, the only way the search engine is going to find your Model3809.htm page is if you link it up.

When you linked this page before all you had to do was use the Product Id like this: " product.asp?Id=4", so lets take that Product Id and create a function that returns the correct URL.

<%
Function CreateProductURL(lProductId)
strSQL = "SELECT Product_Model FROM Product " _
	& "WHERE Product_Id =" & lProductId
Set oRS = oConn.Execute(strSQL)
If (Not oRS.EOF) Then
	strModel = oRS("Product_Model")
End If
CreateProductURL = "/" & strModel & ".htm"
End Function
%>

Now when you want to add a URL you do it like this:

<A HREF="<%=CreateProductURL(4)%>">DishWasher</A>

Note: In this example we assume you don't know the model name and you have to go back to the database -- in the real world this might not be the case. You know the model name and can create the URL without making another call to the database.

Performance

There are some obvious performance issues associated with this technique. First, it might require an extra database call to create the well-named URLs that don't exist. Secondly, it will always require an extra database call to figure out the correct URL from the 404 URL. Finally, the two Server.Transfers are expensive. However, you can solve some of the performance problems using XCache. XCache will resolve the 404 URL to the right page and cache this information for later requests.

Example

An example of this can be seen with http://www.kulshan.com. Most of the leaf pages on Kulshan.com, like the individual restaurants reviews, use this technique to get better search engine placement. Kulshan.com also uses XCache.

Summary

Create URLs that you can market and that work on search engines is fairly easy, if you don't have to create the directory structure and files that those URLs represent. Using IIS 5.0 Custom Error Page technology and handling the 404s can yield great pages names.

Post Point Software

Founded in 1996 by Wayne and Dina Berry, Post Point Software is a lead innovator of Web caching software and Internet performance solutions. The company's flagship products XCache, XBuilder and XTune provide Web developers and site owners with robust performance solutions that significantly improve site experiences for their end users. Headquartered in Bellingham, Washington, Post Point received initial funding from iStart Ventures. For more information, visit www.postpointsoft.com or email info@postpointsoft.com.

Related Articles


Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers