When you run a website, there are times that you’ll need to redirect older webpages to newer webpages or you might want to redirect multiple domain names to a single domain name. There are two key ways to accomplish this task, issuing a 301 redirect or a 302 redirect. What you might not know is that a 301 redirect is search engine friendly and a 302 redirect is not. 301’s will safely tell the search engines that one page has been permanently moved to a new location, while 302’s tell the search engines that it’s a temporary redirect (which can cause problems down the line.) This shouldn’t be news for anyone working in the search industry, but might be news for website owners outside of the industry. My post today isn’t about what 301’s and 302’s are, but it’s about a unique challenge I ran into recently with one of my clients. We needed to 301 redirect several HTML files to new pages on the website without using the standard methods of issuing a 301 redirect. Also, the website was running on a shared server, which was an added barrier. By writing this post, my hope is that I can help some of you who might run into the same situation. More on this soon. Let’s start with a quick review of redirects.
Let’s Define 301 and 302 redirects:
A 301 redirect is a permanent redirect and tells the search engines that the old webpage has been permanently moved to a new location. It basically tells Google and the other engines that you have permanently moved one page from HERE to THERE. If you need to redirect a file on your website, then you should always use a 301 redirect.
A 302 redirect is a temporary redirect, and is not search engine friendly. It basically tells Google and the other engines that the file in question has temporarily moved from HERE to THERE. There have been vulnerabilities in the past with using 302 redirects, which is a reason that 302’s aren’t trusted. If you need to redirect one page to another on your website, then don’t use a 302. Always use a 301 redirect when possible.
The 301 Challenge
Back to the redirect challenge that I recently faced. Again, my hope is that the solution can help some of you who might run into the same situation. One of my clients has a website that’s running on a windows server and contains a combination of HTML, ASP, and ASP.net files. We needed to redirect several older HTML pages to new ASP.net pages, which at first glance would be relatively simple to do. If you are on a windows server, I highly recommend using ISAPI rewrite to issue 301 redirects. This is similar to using an .htaccess file on a linux or unix server. You can issue one line commands using a text file named httpd.ini that sits at the root level of your website. It easily enables you to issue 301 redirects, rewrite URLs, etc. It’s a great utility to have installed…
The Shared Server Problem
Here was the problem. We couldn’t use ISAPI rewrite. The website was running on a shared server and the web hosting company would not install ISAPI rewrite on the server. Some hosting companies will and others won’t…this specific hosting provider wouldn’t after several requests to do so.
Issue the 301 Via ASP.net Code
So, my next move was to issue the 301 redirects via code (either through ASP or ASP.net). There was also a problem with using this technique. The files we needed to redirect were HTML files and not ASP or ASP.net files, so I couldn’t add the necessary VB or VBScript code to the pages that needed to be redirected. Moving on…
Run HTML Files Through ASP.net
My third idea was to run all HTML files on the website through ASP.net, which would enable me to add ASP.net code to each of the HTML files. Basically, when an HTML file is requested, it would run through the ASP.net engine. Then I could issue the 301 redirect via ASP.net code instead of using ISAPI rewrite. Cool, right? The hosting provider made the change on the server (running HTML files through ASP.net), but to our dismay, some of the HTML files on the site were not rendering properly. So, we reverted back to the original setup (where HTML files were not run through ASP.net). Again, moving on…
The Fourth Time is a Charm…
My fourth idea finally worked. The hosting provider basically said we were out of luck, but I wasn’t ready to give up so fast… I knew that Classic ASP is still supported on windows server, even when running ASP.net. Classic ASP was the original version of Microsoft’s server side scripting framework. The next version of the framework was ASP.net, which has also gone through its own upgrades over the years. So, I posed the question…couldn’t we try and run HTML files through Classic ASP instead of ASP.net? My client’s hosting provider made the change and bingo, it worked like a charm. We can now issue search engine friendly 301 redirects on HTML pages. Just to clarify, this meant that I could add Classic ASP code to any HTML file running on the website. For our purposes, I could issue a 301 redirect via Classic ASP code, the HTML file would be run through the Classic ASP engine, and everyone would be happy. :)
The Added Benefits of Using This Solution:
The obvious benefit is that we can now use 301 redirects with any HTML file on the website, when needed. The added benefit is that we can now also use Classic ASP code within any HTML file running on the website. Typically, HTML files can only contain HTML code (no server side functionality.) But with this solution, I can make database calls, provide dynamic content, use session variables, and any other Classic ASP functionality available. It’s a flexible solution, to say the least.
In closing, please remember the following items when you need to redirect HTML files on your website:
1. If you need to redirect a webpage or domain name, use a 301 redirect.
2. Don’t use 302 redirects. If you do, use them at your own peril. {cue mad scientist laughter}.
3. If your website is hosted on a windows server, use ISAPI rewrite to issue your 301 redirects. It’s a great utility.
4. If you can’t use ISAPI rewrite and you are in a shared environment, try and issue the redirect via ASP or ASP.net code. If you are trying to redirect HTML files, you’ll need to skip to #5 below.
5. If you can’t add ASP.net or Classic ASP code because you are working with HTML files, then try running your HTML files through the ASP.net or Classic ASP engine. Then you’ll be able to add the 301 redirect code to your HTML files.
Happy Redirecting!
GG