Mapping Dynamic Web pages with static URLs

Source: Internet
Author: User
Tags add end error handling iis implement query string domain name
Dynamically generated Web pages are essential when constructing truly large Web sites. However, the name of the dynamic page (that is, its URL) often lacks a clear meaning. For example, name is product. Asp? Id=4 's page is not always as good as the page named/applicances/dishwashers/model3809.htm. This article describes how to implement a static page name and dynamic page mapping.

Overview
The other advantage of static page names, in addition to having a more explicit meaning, is that search engines can index these pages. Most search engines, such as Alta Vista and Yahoo, do not retrieve pages with question marks in their URLs because they worry about entering a never-ending maze of links. After the dynamic page name is converted to the static page name, the search engine will index and classify the pages, thus bringing more traffic to the site.
To use the method described in this article to convert a dynamic name to a static name, you must use Windows 2000 and IIS 5.0. Two improvements to IIS 5.0 enable us to implement this transformation by using Server.Transfer's "Custom error message" feature and the ability to use Server.Transfer in ASP pages. Although IIS 4.0 also supports custom error messages, it uses Response.Redirect and is not available, so this article method requires that IIS 5.0 be used. Response.Redirect is not used because search engines do not follow redirects.
Using the methods described in this article, Web developers first use static-style URLs to link pages that do not actually exist. Then set up the IIS server and tell it to use the specified ASP page (404.asp) to handle all 404 errors that appear on the site. In this 404.asp page, the original URL is converted to a formal dynamic URL, executed using Server.Transfer and returned to the user's browser to the target page.
Suppose you have the following URL:
Http://www.myserver.com/applicances/dishwashers/kenmore/Model3809.htm
Where myserver.com is replaced by the site's domain name, the URL returns a 404 error. The first thing we need to do is to use a specific. ASP page to handle all these 404 errors. This can be accomplished with the custom error message feature of IIS 5.0. The procedure for setting this feature is as follows:
To open IIS Server Manager in MMC
Right-click the Web Site node and choose Properties
Click on the "Custom error message" page
Scroll down until 404 error is found
Double-click the 404 error to open the Error Mapping Properties dialog box
Change message type to URL
Enter "/404.asp" in the URL box
Click "OK" to close the window
Now 404 errors have been made by 404. ASP handled it. When IIS invokes the 404.asp page, it provides the URL that caused the 404 error, which is very useful for us.
Error Handling page
Next we create 404 of the processing errors. ASP page. The first thing to do is to get the name of the page that caused the 404 error. The following line of code extracts the name of this page from the query string:
<%
' Get the page name
STRQ = Request.ServerVariables ("query_string")
% >
So what is important in the STRQ? In the example above, it should look like this:/applicances/dishwashers/kenmore/model3809.htm. All we really need is the Model3809 (product model), because this is the only key in the product database. The following lines of code identify the product ID (number) based on the product model:
<%
' Calculate product model
nindex = InStrRev (STRQ, "/")
If (nindex >0) Then
Strmodelnumber = Right (Strq,len (STRQ)-nindex)
STRQ = Left (strq,nindex-1)
End If
 
' Remove the. htm suffix from the product model
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, (strpagename) -3,1) = ".") Then
 
Strmodelnumber =left (Strpagename,len (Strmodelnumber)-4)
 
End If
 
' Find the product number from the product 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 number, we must save it before converting to the correct ASP page. We cannot pass the product number (which is a limitation of IIS) through the Server.Transfer in the query string, so it must be passed through the session object.
<%
Session ("Id") = Lproductid
Server.Transfer ("/product.") ASP ")
% >
When you execute this page, the contents of the browser's address bar are as follows:
Http://www.myserver.com/applicances/dishwashers/kenmore/Model3809.htm
Because of the use of Server.Transfer, the URL in the browser's address bar will not change, the same browser does not need to interact with the server again, which is different from the Response.Redirect.
Also note that the directory in the URL does not exist at all, and in fact, the rest of the URL in addition to the server name does not make any difference. For example, the following URLs will return the same page.
Http://www.myserver.com/Model3809.htm
Http://www.myserver.com/trucks/ford/Model3809.htm
So why add so many catalogs? These catalogs will improve the search engine's evaluation of the site. Some search engines think that the words in the URL is more important than the page title and text search keyword, so the directory name is very important.
Calling a page that does not exist
We have discussed techniques to convert URLs that do not exist to valid dynamic URLs. However, to enable search engines to index these pages, we also need to link these non-existent URLs. In other words, only when we link the model3809.htm page will the search engine find it.
When we previously linked this page we simply gave the product number as follows: "Product. Asp? Id=4 ". Now we're going to construct a function that returns the appropriate URL with the product number as the parameter.
<%
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, if we want to add a URL, just follow the following:
< A href= ". /.. /<%=createproducturl (4)% > "> Dishwasher </a >
In this case we assume that we do not know the product model name and must query the database to be informed. But this may not be the case in reality, we know the product model name, you can create a URL directly without having to access the database again.
Performance issues
The methods described in this article can significantly affect performance. First, it requires a database call to create a static-style URL. Second, to get the correct URL from the URL that generated 404, it also adds an extra database call. Finally, two times Server.Transfer requires a larger cost.
However, some performance problems can be solved with XCache (www.postpointsoft.com). XCache can convert the URL with the 404 error to the correct page and cache the information for subsequent requests.
Instance
Please visit http://www.kulshan.com, an example of how this technique is applied. Most of the kulshan.com's branch pages, such as restaurants and hotel reviews, are used for higher ratings in search engines. Kulshan.com also used the XCache.
Summary
Use the custom error information feature of IIS 5.0 to control 404 errors You can create a static page-style URL for a dynamic page. As long as you do not need to create the directories and files used by these static URLs, it is fairly straightforward to create a URL that is both conducive to marketing and to the search engine rank.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.