• JLH Design

  • 301 Redirects Revisited for Products and Categories Pages

29th August 2006

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.

  1. 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.
  2. If you want to forward them to a different category that has products under it:
    1. Change the category name to 301P
    2. Disable the category
    3. 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.
  3. If you want to forward them to a different category that has other categories under it:
    1. Change the category name to 301C
    2. Disable the category
    3. 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)

And for kicks, this one redirects the non-www version of a category page that does not exist at all to the www version of the categories page.

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)

posted in Ecommerce, Webmastering | 0 Comments

11th August 2006

EcommerceTemplates and Proper 301 Redirects in ASP


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 love the ecommercetemplates shopping cart solution, but there is one thing that has annoyed me since I started working with them. If you have to remove a product, as often happens, the user sees a basically blank page with the note:

Sorry, this product is not currently available

Not very appealing, and doesn’t really help your customer much. Much worse however, is that if that product was indexed by a search engine and the page had some ranking, you’ve lost all value. The same message is also given if someone accidentally links to a non-existent product, or makes a mistake in the link. Often manufacturers will change a product and upgrade it to something better and you have to remove the old product and add the new product, also loosing all of your search engine credit.

We need a way to tell Google and the rest that the product the searcher was looking for is no longer available, but can be found at this new location. When we tell them that all value the old page should be saved and moved to the new page.

The 301 redirect accomplished just that mission, but now I needed to find a way to do it with the current database structure so that it was automatic. By modifying your proddetail.asp page with the following code you will have accomplished a proper 301 redirect under three different occasions.

  1. The first part deals with canonicalization. If someone reaches your site at http://yoursite.com but you really want them to use http://www.yoursite.com we redirect them to the right URL. Since you probably have dynamic pages that pass on parameters, this code accomplishes that as well. As a matter of fact this should be placed on the top of every .asp page you’ve got, I’ll show that separate code later.
  2. If you have moved a product or no longer offer a product, but would like the visitor to go to the best available choice, they will be automatically forwarded. The search engines will also transfer all value and links to the new page.
  3. If someone mistakenly types in a wrong url, or a bad link sends them to a product that doesn’t exist we will be able to send them to some navigation structure.

The following code should be placed at the top of your proddetail.asp page below the includes for the database connection and metainfo. It assumes that you are using meta descriptions and titles, and if you are not, do it now! Your search engine rankings will thank you.

<%

'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 productname= "301" then
Response.Clear
Response.Status ="301 Moved Permanently"
Response.AddHeader "Location","http://" & Domain & "/proddetail.asp" & "?prod=" & productdescription
Response.End
end if

If productname= "" then
Response.Clear
Response.Status ="301 Moved Permanently"
Response.AddHeader "Location","http://" & Domain & "/categories.asp"
Response.End
end if
%>

After that is done, we need to edit the products.

If you simply delete a product they will be sent to your categories page. However, if you’d like to give them a better choice and send them to a suggested product instead open up the product that is no longer available:

  1. Leave the product ID (Reference) alone
  2. Change product status to not display
  3. Change the product name (Prod Name) to: 301
  4. Change the product description (short) to the product ID of the product you want to send them to.
  5. Save the product

Now visit the old product url, it should automatically send you to correct product.

Just to make sure everything worked Check Your HTTP Headers by entering the old product URL, you should see a 301 redirect to the new page, then a 200 at the new page. While your on that site be sure to check the other redirects. Try the URL without the WWW, and then try going to a product detail page for a product that doesn’t exist.

For the other asp pages on your site, you’ll want to redirect those as well to the www version, the following code should be entered before the first “HEAD” tag. See this post about the complete explanation of 301 redirecting for canonicalization and downloads including to the non-www version.

<%
'This code will redirect any asp page to the www version
'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_Name, theURL, QUERY_STRING, HTTP_PATH,TEMP_NUM
'Get domain that the page is on
Domain_Name = lcase(request.ServerVariables("HTTP_HOST"))
'Check if URL is the www version
if left(Domain_Name, 3) <> "www" Then
HTTP_PATH = request.ServerVariables("PATH_INFO")
'Check if page is default.asp if so, redirect to "/".  If other index page is used, such
'as index.asp the numbers in the right and len statement need to be changed, as well
'as the IF statment to indicate the index page.
If right(HTTP_PATH, 12) = "/default.asp" Then
TEMP_NUM = len(HTTP_PATH)-11
HTTP_PATH = left(HTTP_PATH,TEMP_NUM)
End If
' Sets the new URL settings with correct page
QUERY_STRING = request.ServerVariables("QUERY_STRING")
theURL = "http://www." & Domain_Name & HTTP_PATH
'This section passes on the query string variables
if len(QUERY_STRING) > 0 Then
theURL = theURL & "?" & QUERY_STRING
end if
' Send 301 response and new location
Response.Clear
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", theURL
Response.Flush
Response.End
end if
%>

posted in Ecommerce, Webmastering | Comments Off

  • Please Support

  • Marquette University

  • Sponsored

125x125

  • Donations


  • ;

Enter your email address:

Delivered by FeedBurner

rss posts
  • Readers