404 Trick for Web Promotion - Linking
(Page 3 of 4 )
What do you do to switch from one product to another product? Certainly, we create a link and get the product id from the database and place it in querystring. Such as:
<a href="product.asp?id=<%=ID%>"><%=Product_name%></a>
But now you should change it. Instead of passing the product id with querystring, you need to get the corresponding PageName and redirect to that page. Such as:
<a href="<%=PageName%>"><%=Product_name%></a>
It will now redirect to:
www.mysite.com/DVD-to-pocket-PC.htm
At this stage we get a static looking URL. That page does not really exist, but we code it in 404.asp to handle it and execute the original page.
Creation of the 404.asp page
Now we need to create the 404.asp page to handle all 404 page not found errors. For this purpose we need to get the name of the page that had the 404 errors. As I already say, IIS sends the name of that file with querystring. So we need to get querystring.
<%
' Getting page name
dim PageName
PageName = Request.ServerVariables("QUERY_STRING")
%>
Here we get the page, such as DVD-to-pocket-PC.htm, in the PageName variable. Now we have to search the database for this page, and get the product id corresponding that page. It can be done as:
<%
' Product id
dim ProductID
set obj = Server.CreateObject("ADODB.RecordSet")
obj.Open "select ID from TABLE_NAME where PageName = '"&PageName&"' ", DBCon
if not obj.EOF then
ProductID = obj.Fields("ID")
REDIRECTING TO ORIGNAL PAGE
Else
CODE FOR PAGE NOT FOUND
End if
%>
We simply get the ID and store it in ProductID. If that page does not exist in our database, it means it is really a 404 error. So we need to inform the user that this page does not exist; please try other pages. If possible, give a search box so that the user can search for the desired product from your website.
Next: A Well-Designed Error Page >>
More Website Promotion Articles
More By Burhan Khan