301 Redirects Revisited for Products and Categories Pages
Warning: copy() [function.copy]: Filename cannot be empty in /home/jlhdes/public_html/wp-content/plugins/mytube/mytube.php on line 220
Update 8/31/06 the following codes can now be downloaded for the products, categories, and proddetail pages for 301 redirects on ecommerce templates in asp. I’ve also done post on 301 redirecting for fixing canonicalization problems on an IIS Server.
I previously discussed setting up the Ecommerce Templates software in ASP to do permanent redirects for products that were moved or no longer available. The implimentation of that has been hugely successful, the search engines were still looking for old products and are now starting to crawl the new products more. I used to get 150 to 200 crawls a day to the old products, now about a month or so its less than 10.
So I set out to find a way to set up the products.asp and categories.asp pages to do a 301 permanent redirect. This proved to be a bit more difficult than the productdetail.asp page as the pages can exist without any server variables (ie. categories.asp alone) and categories come in two types, one has products listed under it and the other has other categories listed under it. As before I wanted to design the system to redirect the user and spider to a new category if directed or to the base category page if no specific new category is offered. If a person or spider attempts to reach a category that does not exist anymore, or never did, and a better one is not suggested it defaults to the categories page.
First off, let’s get the coding out of the way.
Open up your products.asp and categories.asp files in notepad. As before I assume you have already set up the dynamic meta descriptions and titles, if not DO IT NOW as the included files to database and metainfo need to be the first lines in the file. The code below also included the standard concicalization 301 redirect as well. This will redirect the user and bot to the www version of the website automatically, avoiding duplicate content in the search engines.
<%
'This code is provided as-is with no guarantee or warranty
'It is provided for free distribution as long as these comments
'are left in place.
'Designed by www.jlh-design.com 2006
Dim Domain
Domain = lcase(request.ServerVariables("HTTP_HOST"))
If sectionname= "301C" then
Response.Clear
Response.Status ="301 Moved Permanently"
Response.AddHeader "Location","http://" & Domain &
"/categories.asp" & "?cat=" & sectiondescription
Response.End
end if
If sectionname= "301P" then
Response.Clear
Response.Status ="301 Moved Permanently"
Response.AddHeader "Location","http://" & Domain &
"/products.asp" & "?cat=" & sectiondescription
Response.End
end if
If catid <>"" then
If sectionname= "" then
Response.Clear
Response.Status ="301 Moved Permanently"
Response.AddHeader "Location","http://" &
Domain & "/categories.asp"
Response.End
end if
end if
%>
Operating the Redirect in Ecommerce Templates
All right after you’ve got that done in order to manage the categories you have three options for a category you want to delete.
- The easiest is to just delete the old category, the user and the spiders will be forwarded to your categories.asp page where they can navigate to a category that exists.
- If you want to forward them to a different category that has products under it:
- Change the category name to 301P
- Disable the category
- Enter the new category ID in the description. Note: this is the NUMBER of the category shown in parenthesis not the name of the category.
- If you want to forward them to a different category that has other categories under it:
- Change the category name to 301C
- Disable the category
- Enter the new category ID in the description. Note: this is the NUMBER of the category shown in parenthesis not the NAME of the category.
That’s it you are done.
As before it’s a good idea to check your server headers to make sure everything is working. A great tool for doing this is the Oy-Oy Search Engine Tools.
To see the redirects in action, try the following links.
Redirects from an old product number X4212 to new number X4213
The headers should read:
URL=http://www.hvac-direct.com/proddetail.asp?prod=X4212
Result code: 301 (MovedPermanently / Moved Permanently)
New location: http://www.hvac-direct.com/proddetail.asp?prod=X4213
URL=http://www.hvac-direct.com/proddetail.asp?prod=X4213
Result code: 200 (OK / OK)
Redirects from old category 4139 to new category with categories under it 318
The headers should read:
URL=http://www.hvac-direct.com/categories.asp?cat=4139
Result code: 301 (MovedPermanently / Moved Permanently)
New location: http://www.hvac-direct.com/categories.asp?cat=318
URL=http://www.hvac-direct.com/categories.asp?cat=318
Result code: 200 (OK / OK)
Redirects from old category 4140 to new category with products under it 343
The headers should read:
URL=http://www.hvac-direct.com/categories.asp?cat=4140
Result code: 301 (MovedPermanently / Moved Permanently)
New location: http://www.hvac-direct.com/products.asp?cat=343
URL=http://www.hvac-direct.com/products.asp?cat=343
Result code: 200 (OK / OK)
The results should read:
URL=http://hvac-direct.com/categories.asp?cat=13242340
Result code: 301 (MovedPermanently / Moved Permanently)
New location: http://www.hvac-direct.com/categories.asp
URL=http://www.hvac-direct.com/categories.asp
Result code: 200 (OK / OK)


