How To Do A SEO Friendly 301 Redirect on IIS For Static PDF Or HTML files
Say you just took over a website but you want to move the content to your own new domain without losing the page rank and you do not want to take search engine pentalty of hosting duplicate content but you are not sure how to do this using IIS. If you were running apache, you would just edit your .htaccess file to do a simple url rewrite but you are not running apache. So what do you do?
Here is a work around where you simply name a directory, /oldfilename.pdf/ and add this code to your default.asp for this newly created directory:
<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader("Location", "http://new-server.com/new_directory/newfilename.pdf")
Response.End()
%>
In this way you will see this url: "http://original-server.com/oldfilename.pdf" that will actually be "http://original-server.com/oldfilename.pdf/default.asp" running the code above giving you a Google friendly 301 redirect for a static file.
Here is an example:
- I have a text file link on another domain of mine http://net4psp.com/links.txt that I need to permanently move to http://net4geeks.com/links.txt.
- First I go to the old domain's file location, move the links.txt file to the folder where my new domain is hosted.
- Then I create a directory that looks like a file name but it is really a directory. In this case it will be a directory named ./links.txt
- In this directory I create an aspx file that is named to whatever you have set in your default content page for your site. In my case it is default.aspx.
- I add the following code to that file:
<%@LANGUAGE="VBSCRIPT" %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "http://net4geeks.com/links.txt"
Response.End
%> - Now when the old link, http://net4psp.com/links.txt, is crawled, a friendly 301 redirect to the new domain link, http://net4geeks.com/links.txt will redirect the page correctly. This example is on a Windows 2003 server (IIS 6). If you are running Windows 2008 Server (IIS 7), there is an easier way in the your website configuration and this work-around is not recommended. To do a SEO friendly 301 permanent redirect with Windows 2008 Server - IIS 7, just add this to your web.config file:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect static files" stopProcessing="true">
<match url=".links\.txt" />
<conditions>
<add input="{HTTP_HOST}" pattern="^net4psp.com$" />
</conditions>
<action type="Redirect" url="http://www.net4geeks.com/links.txt" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
</configuration>
Note: You will need to install the IIS 7 URL Rewrite module.
For more information and to download the module, see URL Rewrite.
Download the x86 version of the URL Rewrite module
Download the x64 version of the URL Rewrite module
Upgrading from Go Live release
If you already have the Go Live release of URL rewrite module installed the installation package will upgrade it to URL Rewrite version 2.0. All rewrite rules in your ApplicationHost.config and Web.config files will be preserved.
ASP.NET update
The URL Rewrite module installer package includes an ASP.NET update that fixes ASP.NET bugs specific to the URL Rewrite module. SPecifically, the update contains fixes for the following bugs:
- ~ operator in ASP.NET Web server control is resolved incorrectly when using URL Rewrite.
- ASP.NET SiteMap.CurrentNode property returns null when sitemap contains virtual URLs.
The update is applied only if the machine where URL Rewrite module is being installed has .NET Framework version 3.5 SP1 or higher. If you install the required version of the .NET Framework after you install the URL Rewrite module, you can apply the ASP.NET update by running the URL Rewrite module installer and then selecting the Repair option in the installer dialog.
For more details about these and other ASP.NET issues related to URL rewriting, see URL Rewriting for ASP.NET Web Forms.
Read on to see how to configure HTTP redirects on IIS 7 through the IIS manager.
Setting Up A HTTP Redirect Using the IIS 7 Manager
The first and most simple of the redirects will go from one domain to another, useful if you are changing domain names. I have setup the following two domains TSOriginal.com and TSRedirect.com on my test server as you can see:

As you can see, we setup the original domain as TSOriginal.com and have put a simple index.html file in place that looks like this:

Here are the steps required to setup a redirect to our target domain TSRedirect.com. If it works correctly then we should see the new index.html page below:

1. Open IIS Manager by going to Start -> Administrative Tools -> IIS Manager

2. Once IIS Manager opens, expand the WebServer, then the Sites folder, and choose the domain, in this case TSOriginal.com.

3. Click on HTTP REDIRECT in the main panel

4. Place a check next to Redirect requests to this destination: and fill in the target url in the text box below. In this instance it will be TSRedirect.com.

5. In the Redirect Behavior we have several decisions to make about how we want the redirects to work. Let’s explore each of these options.
- Redirect all requests to exact destination – If this object is checked all requests no matter what the original destination will be redirected to the exact location in the text box above. If unchecked everything will be redirected relative to the destination.
- Only redirect requests to content in this directory (not subdirectories) – By default, when you enable redirection, content can be served by subdirectories below the main directory. If you choose this option you can limit requests to just the directory you want without effecting the subdirectories.
- Status Code – In this drop down you choose which status code to return when redirecting. As discussed earlier in this article your options are 301, 302, and 307.
6. For this example we will leave everything unchecked and set a status of 301 in the dropdown menu. Click Apply to set the options.

7. The changes are now in place and if we navigate to TSOriginal.com it will redirect us to TSRedirect.com.
To test if the 301 status redirects correctly we will use the live HTTP headers plugin for Firefox. It will allow us to see the status codes. Here are the results for the test:

As you can see from the highlighted area the status was returned 301.
All requests now for TSOriginal.com will be sent to TSRedirect.com with a 301 status code relative to the domain name.
Redirect a Single Page to Another Page on the Same Site
This type of redirect is especially useful when you might have some temporary changes to a webpage because of seasonal or holiday changes.
In the case of a seasonal page that will return to normal after a short time, it is best to use a 302 redirect. This lets search engines and other sites know that this change is expected and not to change their index or links.
For this example we have removed the site redirect we had placed on TSOriginal.com, and added two pages of content to the site:
oldpage.html

newpage.html

Now let’s setup a temporary 302 redirect from oldpage.html to newpage.html while.
1. Select the site in IIS manager that you want to set the redirect for.
2. In the Features window switch to Content View, Right click on the page you want to work with, oldpage.htm in this case, and left click on Switch to Features View

3. The page now selected in the Connections Pane, click on HTTP Redirect in the features pane

4. Check the box next to Redirect requests to this destination, and fill in the destination page newpage.htm and set the dropdown menu to 302, and click Apply.

5. Navigate to the page TSOriginal.com/oldpage.htm we will be redirected to TSOriginal.com/ newpage.htm.
Use the Live HTTP Headers plugin for Firefox to view the redirect. As you can see the pages redirect with the correct 302 status code.

Redirects can also be setup using Appcmd.exe at the command line, take a look at the Live HTTP plug-in for Firefox.