SEO

ISAPI Rewrite: Addressing Canonicalization and Redirects on Windows Server

In previous posts, I’ve mentioned the importance of having a clean and crawlable website structure for SEO.  The reason is simple.  Without one, you’re dead in the water from an SEO standpoint.  If your content cannot be crawled and indexed, then you can forget about the other aspects of SEO, including content optimization, linkbuilding, etc.  As part of my SEO technical audits, it’s usually not long before the important topic of canonicalization comes up.  Canonicalization is the process of ensuring you don’t provide the same exact content at more than one URL.  In a nutshell, you want to minimize (or eliminate) the number of URL’s that hold identical content, or you can run into duplicate content issues.

A simple example of duplicate content would be a product detail page on an eCommerce website that resolves at five or ten different URL’s.  That’s typically due to filtering (selecting color, size, style, etc.)  There are several ways that a website can present canonical issues and you definitely want to have a plan in place for handling those problems.  For example, does your site resolve with both non-www and www, do your pages resolve with both http and https, do folders resolve with and without trailing slashes, etc.  Handling canonicalization typically includes 301 redirecting requests for potential duplicate content to the canonical url.  For example, redirecting a non-www request to the www version of the page.

Sorting & Filtering On e-Commerce Sites Can Cause Duplicate Content If The URL Changes Based on the Selection:

isapi rewrite canonical ISAPI Rewrite: Addressing Canonicalization and Redirects on Windows Server

The Importance of Redirects (Beyond Canonicalization)

In addition to handling canonical problems, it’s important to have a solid 301 redirection system in place for other situations.  For example, are you going through a site redesign, moving core pieces of content, removing campaign landing pages, etc.  If so, 301 redirects need to be in place or you run the risk of paying dearly in organic search.  There are times I’ve been pulled into projects after the fact, and I can tell you those meetings aren’t pretty.  When reviewing organic search trending, you can almost pinpoint the day that changes took place. If even a few dozen URL’s change, the situation can be bad enough.  But what if hundreds, thousands, or even millions of URL’s change?  The largest site I ever led SEO for contained close to 20 million webpages and went through a massive redesign prior to my arrival (where millions of URL’s changed overnight).  Needless to say, that was one of the first major projects we needed to tackle.

Example of Organic Search Trending If 301 Redirects Aren’t In Place

isapi rewrite traffic ISAPI Rewrite: Addressing Canonicalization and Redirects on Windows Server

ISAPI Rewrite: .htaccess for Windows Hosting

Based on the situations I explained above, what is the best solution for addressing canonicalization, redirects, etc? If you enter some searches in Google, you will overwhelmingly see references to .htaccess and mod_rewrite in the search results.  Using mod_rewrite is definitely a great solution….but only for sites running Apache (primarily under linux hosting).  What about sites running on windows hosting?  Over the past several years, I’ve received a lot of questions from developers and online marketers about what they should utilize for their .net-driven websites.  I started developing with ASP in 1995 and then migrated to ASP.net in the late nineties, so I ran into this topic relatively early on.  The good news is that there is a solid solution for windows server, it’s relatively easy to set up, and you’ll be able to tackle most of what .htaccess can do.  It’s called ISAPI Rewrite and I don’t think it gets as much love as it should!  :)  I still find many companies running their sites on windows server that haven’t heard of it or aren’t currently using it.  Subsequently, they have either developed a custom solution for handling redirects or aren’t doing anything at all with regard to canonicalization.

What is ISAPI Rewrite?

ISAPI Rewrite is an IIS filter that enables you to handle URL rewriting, redirects, etc. via regular expressions.  There are two versions you will come across.  Version 2 has been in use for some time and it’s what I will focus on below.  Version 3 enables you use .htaccess files so you can use the same directives that you are using with sites hosted on linux (and Apache server).  ISAPI Rewrite (version 2) uses an httpd.ini file to add rewriting rules (similar to adding directives to an .htaccess file).  Version 3, on the other hand, was built to mimic .htaccess for Apache.  Based on how popular .htaccess has been for handling URL rewriting on Apache, the makers of ISAPI Rewrite developed a solution that enables you to write the same code for .htaccess and ISAPI Rewrite.  That was a brilliant move, so you can easily port rules from one site you are working on to the next (regardless of platform).  Note, not all directives that are used in .htaccess for Apache are supported by ISAPI Rewrite 3.  However, you will find most are.  You can read the compatability chart to learn more.

There Are Two Versions of ISAPI Rewrite:

isapi rewrite 2 3 ISAPI Rewrite: Addressing Canonicalization and Redirects on Windows Server

I’ve used ISAPI Rewrite extensively and I highly recommend it.  I’ve found it to be a great solution for most websites.  There were only a handful of times that it wasn’t the best solution.  For example, we didn’t use ISAPI Rewrite for the website I mentioned earlier that contained 20 million webpages. For that specific site, our web architect decided to build a custom URL rewriting solution based on his extensive knowledge of the site architecture (and the size and complexity of the website.)  But, that was a rare situation.  From a pricing standpoint, ISAPI Rewrite is extremely reasonable.  A single server license is only $99, which is a small price to pay considering the impact it can have SEO-wise.  If you are on a shared hosting plan, the price might even be better.  Your hosting provider might already have the filter installed.  More about shared hosting below.

A Note About Shared Hosting and ISAPI Rewrite

If you are running a site on a windows hosting plan and don’t have a solid redirection plan in place, then call your hosting provider immediately and ask them to install ISAPI Rewrite.  If you have a dedicated server or virtual private server, then you can install it yourself.  The installation will take just a few minutes.  Note, be aware that some hosting providers will not install ISAPI Rewrite on a shared hosting plan.  There are several reasons that they might give you for not installing it, including that the installation could impact other sites hosted on the same server.  That said, I have found a few hosting providers that were willing to do this for my sites and client sites, so you just might be in luck.  I recommend pushing to have it installed…   You can just blame the guy on Search Engine Journal who recommended it. ;)  If you are in a situation where your hosting provider won’t install ISAPI Rewrite, you might have to get creative with how you handle canonicalization and redirects.  For example, you can read my post titled 301 Redirecting HTML Files Without Using ISAPI Rewrite.  That was a situation where I refused to take no for an answer, and the final solution ended up working well.

Some Examples of Using ISAPI Rewrite

Now that you’re (hopefully) excited about using ISAPI Rewrite, I’m sure you are wondering how it works and what some of the rules look like.  Based on the endless number of situations you can tackle, I couldn’t possibly include them all in this post.  However, I know there are certain situations you will come across often in SEO and I have provided those examples below.  For example, redirecting non-www to www, redirecting entire domains to other domains, redirecting specific pages, forcing trailing slashes on folders, etc.  The examples provided below are for ISAPI Rewrite Version 2 (since version 3 would be the equivalent of using .htaccess for Apache).  Since ISAPI Rewrite is based on regular expressions, some of the directives included below might look foreign.  If you plan to write your own custom directives, you should get familiar with how regular expressions work.  That’s beyond the scope of this post, but is worth noting.  Also, ISAPI Rewrite has a solid support site, along with a forum, so you should be able to get answers to your specific questions there if needed.

Note, for the examples listed below, place the following directives in an httpd.ini file located in the root directory of your website.  It’s optimal if you use a text editor to work on the file.  Also, make sure the first line of the file is:

[ISAPI_Rewrite]

Redirecting One Page to Another

Let’s say you have a product page that has built up 750 inbound links, but that product is going through a major update.  Unfortunately, the URL of the new product page will be different than the old product page.  Therefore, you want to redirect the older page to the new one. Hit enter a few times after the first line you entered above and then enter:

RewriteRule /oldproduct.htm http://www.yourdomain.com/newproduct.htm [I,O,RP,L]

Redirecting Non-www to www

This should be one of the first rules you implement.   In SEO, you don’t want your site to resolve as both non-www and www.  To handle this situation, you can use the simple rule below to force any request for non-www pages to the www equivalent.

RewriteCond Host: ^yourdomain\.com

RewriteRule (.*) http\://www\.yourdomain\.com$1 [I,RP]

Redirecting Domain Names

For argument’s sake, let’s say you own two domain names and one is the core domain that you use for your website.  Maybe the second domain is catchy and is great for marketing materials.  For this situation, you would want to 301 redirect any request for the second domain name to the equivalent page on the first.  You don’t want both domains to resolve with the same content (as mentioned earlier in my post).

RewriteCond Host: ^www\.catchydomain\.com

RewriteRule (.*) http\://www\.yourdomain\.com$1 [I,RP]

Forcing Trailing Slashes on Directories

If you have content that resolves directly at the folder level on your website, then this rule will ensure that those directories always end with a trailing slash (versus some resolving with or without a slash).  i.e. www.yourdomain.com/directory/ versus www.yourdomain.com/directory

RewriteRule ^/([^.?]+[^.?/])$ /$1/ [I,R=301]

Summary

I hope this introduction to ISAPI Rewrite enables you to effectively address canonicalization and redirects on your windows-hosted websites. I think you’ll find it to be a great solution that can handle most of the sites you are working on. If you are new to ISAPI Rewrite, I recommend setting it up (or having your hosting provider install it) and then testing out various situations. My guess is you’ll be up and running in no time.

Now, if only canonicalization were easier to pronounce. icon smile ISAPI Rewrite: Addressing Canonicalization and Redirects on Windows Server

Glenn Gabe is an online marketing consultant at G-Squared Interactive and focuses heavily on SEO, SEM, Social Media Marketing, Viral Marketing and Web Analytics. You can read more of Glenn’s posts on his blog, The Internet Marketing Driver and you can follow him on Twitter to keep up with his latest projects, news, and updates.

 ISAPI Rewrite: Addressing Canonicalization and Redirects on Windows Server
Featured SEO Writer for SEJ Glenn Gabe is a digital marketing consultant at G-Squared Interactive and focuses heavily on SEO, SEM, Social Advertising, Social Media Marketing, and Web Analytics. Glenn has over 18 years of experience and has held leadership positions both in-house and at a global interactive agency. During his career, Glenn has helped clients across a wide range of industries including consumer packaged goods (CPG), ecommerce, startups, pharmaceutical, healthcare, military, education, non-profits, online auctions, real-estate, and publishing. You can follow Glenn on Google+ here.

You Might Also Like

Comments are closed.

12 thoughts on “ISAPI Rewrite: Addressing Canonicalization and Redirects on Windows Server

  1. Glenn –

    Absolutely awesome and comprehensive write-up on the ISAPI Rewrite functionality. There is nothing like this post anywhere else and it is so thoroughly done.

    Great job and thanks!

    1. Hi Alex.

      I guess it depends on what you require for your site. Ape includes an entire collection of Apache modules (including mod_rewrite). You might want to start with ISAPI Rewrite and see if it tackles what you need. Then you can move to Ape if needed.

      I hope that helps.

  2. thanks for the advice. i have been using ISAPI trial and like it, but they were selling ape and wanted to know a more subjective view of it.

  3. Great post Glen. I have an issue with a site displaying a duplicate homepage – the canonical version being the root url (/), and the duplicate appending an /index.asp. Can I use ISAPI rewrite to redirect the /index.asp to the root address and consolidate the power into one source?

  4. How do you redirect the default.aspx to the root domain? Also with ISAPI 3, do you name the upload file .htaccess like you do on Apache servers?

  5. How do you redirect the default.aspx to the root domain? Also with ISAPI 3, do you name the upload file .htaccess like you do on Apache servers?