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.
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.
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.
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.
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:
Open IIS Manage In MMC.
Right Click on the web site node and choose properties.
Click on the Custom Errors Tab.
Scroll down until you see the HTTP Error -- 404.
Double click on 404 to open the "Error Mapping Properties" dialog.
Change the Message Type to URL.
For the URL enter in /404.asp
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.
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)
' 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 _
' 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")
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.
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.
strSQL = "SELECT Product_Model FROM Product " _
& "WHERE Product_Id =" & lProductId
Set oRS = oConn.Execute(strSQL)
If (Not oRS.EOF) Then
strModel = oRS("Product_Model")
CreateProductURL = "/" & strModel & ".htm"
Now when you want to add a URL you do it like this:
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.
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.
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.
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 email@example.com.