• JLH Design

  • 301 Redirects in ASP on an IIS Server

31st August 2006

301 Redirects in ASP on an IIS Server


Warning: copy() [function.copy]: Filename cannot be empty in /home/jlhdes/public_html/wp-content/plugins/mytube/mytube.php on line 220

Individual Page 301 redirects

To forward individual pages to a new location in IIS, please see this post.


www to non-www or non-www to www 301 redirects

To fix canonicalization issues of your domain in when using asp on an IIS server, specially in a shared hosting environment, sometimes you need to enter the code in on a page by page basis. Having your host set up the server to parse asp on all pages allows you to use this method on htm and html pages as well.

In developing the code for this I wanted it to have several functions:

  1. Be generic so I don’t need to enter the domain, so I can use the same file on all my domains.
  2. Pass on any server variables for dynamic pages.
  3. Redirect the default.asp page to “/”
  4. work in any subfolder as well for the default.asp fix.

At the top of each page on the site I place an included file calling up either version. The download(below) includes code to forward to the non-www and the www version of your site.

To forward to the WWW version via 301 redirect:

<%
'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

%>

To forward to the non-www version via a 301 redirect:

<%
'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 name the page is on

Domain_Name = lcase(request.ServerVariables("HTTP_HOST"))

' Check to see if www version

if left(Domain_Name, 3) = "www" Then

' Changes http path to non-www version

TEMP_NUM = len(Domain_Name)-4
Domain_Name = right(Domain_Name,TEMP_NUM)
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://" & 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

%>

Download

posted in Webmastering | 13 Comments

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

17th August 2006

New Boiler Group


Warning: copy() [function.copy]: Filename cannot be empty in /home/jlhdes/public_html/wp-content/plugins/mytube/mytube.php on line 220

If you read the resume you know, I know a thing or two about boilers. I started a new group on google groups, follow the above link to see it. The following is a sampling of the type of conversation I hope to get into, its a reply I wrote to a poster about surface blowdown.

You will need to know the pressure of the steam drum to do any
calculations. The degree of superheat isn’t relevant as that energy is
added to the steam.

When you refer to blowdown I assume you mean surface or continuous
blowdown. Bottom blowdown is usually too dirty and intermittent to
consider heat recovery from it. Usually we use the energy from the
surface blowdown and recover it in two different places, as low
pressure flash steam, and with a heat exchanger to preheat the boiler
make-up water.

I’ll run through some of the calculations, but you will need to know
the operating pressure of the boiler, the low pressure equalizing line,
and temperature of make-up water to complete the Calcs yourself.

First off, lets discuss the process. You say that you have a 1%
blowdown rate. For those who don’t fully understand I’ll
elaborate. Let’s say the boiler is running at 100,000 lbs/hr of
steam production. So we are bringing in boiler feedwater with a
certain amount of dissolved solids in it and heating it to boiling temp
and letting the water vapor leave as pressurized steam. As the steam
evaporates it leaves behind the dissolved solids in the water. If we
let it run like this the concentration of solids in the boiler water
would raise higher and higher. Too high of solids concentration leads
to problems such as priming etc. To control the solids left behind, we
drain off some of the boiler water continuously which is replaced with
feedwater with a lower concentration of solids. So using the example
of 100,000 lbs/hr capacity we’ll actually have a feedwater flow rate
of 101,000 lbs/hr with a blowdown rate of 1000 lbs/hr.

The boiler water is at operating pressure and mostly at saturated steam
temperature, so let’s assume for discussion you are running at 250
psig. Referring to a steam table at 250 psig the temperature is 406 F
and the sensible heat in Btu/lb is 382. At 1000 lbs/hr that’s
382,000 btu/hr going down the drain which is probably worth recovering.

Generally there are two components of heat recovery. The first is
flash steam recovery. In our example we are going to drain the water
at 250 psig and saturated temp. This water will go through valves and
to a lower pressure, where it can’t exist as water at this
temperature and pressure, some will flash off as stem. So we take
advantage of this and design the system around it. Generally we take
the blowdown to a flash separator, which is nothing more than a
pressure vessel that brings the water in the side tangentially to the
walls. The water swirls around the outside of the tank, flash steam
rises out the vent on top, and water goes out the drain. (For a
picture visit http://www.pennseparator.com/pbs12.htm) The first
component of our heat recovery is generally to connect this vent to a
low pressure steam usage, such the preheat steam supplied to the
boilers deareator.

Let’s further assume for this example that your dearator is operating
at 10 psig, and the flash steam from our blowdown will go to this.

>From the steam charts steam at 10 psig has a sensible heat of 207

btu/lb, latent of 953 btu/lb at 239 F. So our water is going to go
from having a sensible heat of 382 btu/lb to 207 btu/lb, the difference
is 175 btu/lb. This times the flow of 1000 lbs/hr means we have
175,000 btu/hr of energy released as flash steam. From the steam chart
above 175,000/953=183 lbs/hr of flash steam at 10 psig is produced.
Another calculation is to take the difference of 175 divided by the
latent heat at the equalizing pressure 175/953=0.183 which means we are
producing 18.3% flash steam.

Now we still have the water left over, 1000-183 = 817 lbs/hr of water
at 239 f is available. We’ll then take this water through a heat
exchanger. On one side of the heat exchanger is the cold fresh make-up
water for the boiler system, let’s assume this is at 60 F, we’ll
also assume further that we selected this heat exchanger with an
approach of 20 F, so our blowdown water will be cooled to 80 F before
going to the drain, the energy recovered is then 817 lbs/hr X 1.0
Btu/lb-F X (239-80)F = 129,903 btu/hr.

So our total energy recovered is 175,000 + 129,903 = 304,903 btu/hr.
Our original blowdown had 382,000 btu/hr of energy, so we are
recovering nearly 80% of the blowdown energy available. Selecting the
heat exchanger with a tighter approach will increase the amount of
energy recovered, but maybe be cost prohibitive depending on the size
of the unit.

There are factory built systems above, I’ve personally used the ones
by Penn Separator the most, and have a lot of confidence in their
abilities. Visit http://www.pennseparator.com/home.htm for more
information.

I hope that helps, if you have any more questions, or need to get a
source to size and price them let me know (send an email to the email
address in the profile). John.

posted in Personal | 0 Comments

16th August 2006

Getting Good and Bad Links


Warning: copy() [function.copy]: Filename cannot be empty in /home/jlhdes/public_html/wp-content/plugins/mytube/mytube.php on line 220

It used to be that any link is a good link for your site. It may be true still today, but on a much smaller scale. The algorithims are getting smarter and smarter at trying to sort out which links to count, which to discount, and perhaps, just perhaps which to penalize for.

This article gives 101 ways to get links, some good, some bad. It’s worth a read and well…a link.

posted in 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

9th August 2006

Take my stupid poll, get nothing, I promise.


Warning: copy() [function.copy]: Filename cannot be empty in /home/jlhdes/public_html/wp-content/plugins/mytube/mytube.php on line 220

All righty then, you read the title, and I am ready to offer exactly what is promised. If you take my poll I will offer you exactly nothing in return. Double your money back if you are not satisfied. It’s my promise to you.

posted in Site News | 0 Comments

8th August 2006

Sitemaps expanded to include more Webmaster Tools


Warning: copy() [function.copy]: Filename cannot be empty in /home/jlhdes/public_html/wp-content/plugins/mytube/mytube.php on line 220

Google has taken great leaps forward in communicating to the webmaster how their site is viewed by google, but now is also taking feedback on how they would like it to be seen.

While there has been no evidence at all provided to show that adding a sitemap will actually help a website. They now have the option to help fix conicalization issues to set the prefered domain with or without the www (or dub-dub-dub)

posted in Matt Cutts, Webmastering | 0 Comments

1st August 2006

301 redirect


Warning: copy() [function.copy]: Filename cannot be empty in /home/jlhdes/public_html/wp-content/plugins/mytube/mytube.php on line 220

I’m testing Google’s ability to redirect by 301s. I’ve moved a blog from http://www.hvac-direct.com/blog/ to http://blog.hvac-direct.com. Testing the headers shows a propper 301 and if you click the first link it should take you without effort to the second location. This is a cross domain redirect so it may take them a while to figure it out, I’ll keep you posted.

posted in Google, Webmastering | 0 Comments

  • Please Support

  • Marquette University

  • Sponsored

125x125

  • Donations


  • ;

Enter your email address:

Delivered by FeedBurner

rss posts
  • Readers