November 2010 (1)
August 2010 (1)
July 2010 (1)
June 2010 (3)
July 2009 (3)
June 2009 (1)
May 2009 (1)
February 2009 (1)
January 2009 (1)
November 2008 (3)
October 2008 (4)
September 2008 (9)
August 2008 (6)
July 2008 (3)
June 2008 (3)
January 2008 (1)
November 2007 (2)
October 2007 (6)
September 2007 (5)
August 2007 (22)
July 2007 (6)
June 2007 (1)
May 2007 (3)
April 2007 (27)
March 2007 (8)
February 2007 (6)
September 2006 (2)
August 2006 (4)
July 2006 (9)
June 2006 (17)
May 2006 (20)
April 2006 (12)
March 2006 (9)
February 2006 (4)
January 2006 (3)
December 2005 (2)
November 2005 (4)
October 2005 (5)
September 2005 (37)
August 2005 (83)
July 2005 (6)

Active Directory / LDAP (0)
ASP.Net (19)
Blackberry Development (4)
c# (34)
c++ (3)
Code Camp (1)
Excel (1)
Exchange (3)
Front Page 2003 (6)
FTP User Editor (4)
HTML / CSS / DHTML (8)
IIS (146)
IIS - Log Parser (7)
IIS / FTP (12)
IIS / Tools / Administration (42)
IIS / Tools / Authentication (6)
IIS / Tools / Compression (8)
IIS / Tools / Crash & Hang (12)
IIS / Tools / ISAPI Filters (17)
IIS / Tools / Log Files (17)
IIS / Tools / Scripts (28)
IIS / Tools / Security (9)
IIS / Tools / SSL (6)
IIS 7 (3)
Internet Information Server (1)
Me (Chris Crowe) (6)
MIME Types (1)
Misc (72)
Oulook Express (2)
Silverlight (1)
SQL Server (27)
SQL Server CTE (1)
Vista (15)
Vista Gadgets (8)
Visual Studio (11)
Voice over BroadBand (1)
Windows (33)
Windows Powershell (3)
Windows Sharepoint Services (0)
Windows Sharepoint Services (15)
Windows Vista (14)
Wine Cellar (1)
WMI (8)
Internet Information Server (1) blog.crowe.co.nz.Models.Category

Internet Information Server

Microsoft Internet Information Server Redirection

What does this do and why would I want to know about it?

Redirection is a facility that will allow a user to request one URL and end up being redirected to another URL.

Why would you want this?

  • The site is down for maintenance and you would like to redirect all users to a specific page that lets them know this.
  • You have requests for a particular URL that is no longer valid and would like to redirect the users to the new URL.

How is this done?

The way that this is done is the server sends a response to the client making the request. The client then send another request to the new URL. You can not use this type of redirection to retrieve content from another server and deliver it back to the client. The client makes a new connection to the new URL that is returned.

Below is an example of a HTTP request that is redirected.

== REQUEST ==================
GET / HTTP/1.0
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*
Accept-Language: en-nz
Cookie: .DOTNETNUKE=60BB2849F975471BDDBF
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 1.0.3705)
Host: www.iisfaq.co.nz
Proxy-Connection: Keep-Alive
== RESPONSE =================
HTTP/1.1 302 Object Moved
Location: http://www.iisfaq.com/forum
Server: Microsoft-IIS/5.1
Content-Type: text/html
Content-Length: 150

You an see from the Response that the server has sent an HTTP/1.1 302 Object Moved response (the server can also send a 301 Error response - more on that later). This means that the client then reads the location header and makes a new request to that URL.

How do we actually configure it, and why would we?

There has been redirection features in Internet Information Server for as long as I can remember and almost every one I speak to does not really know how to use it except in the most basic way. This article should hopefully clarify this feature so we all know how to use it when we want to for specific situations that will occur.

What types of Redirection is there available?

Out of the box there is a a pretty simple redirection system employed for IIS.If you are looking for some very specific types of redirection then you may want to investigate ISAPI filters to perform the redirection. An ISAPI filter is a DLL that is configured to process specific requests in the web server. One of those requests can allow us to redirect the user to a different page.

Where can IIS Redirection be configured?

We can configure redirections at the following locations in Internet Services Manager:

  • At a Web Site level
  • At a Physical Directory level
  • At a Virtual Directory level
  • At a Physical File level
  • At a Virtual File level.

Although there are a number of locations that redirections can be configured, the settings are the same for each section so lets just proceed and configure IIS redirection at the Web Site Level.

How to configure IIS Redirection

Below is what you see on the Home Directory tab of the Internet Services Manager for a web site on a Windows XP (IIS 5.1) client machine - this is basically the same for IIS 6 (Windows 2003 Server) but IIS 6 supports Application Pools whereas IIS 5.1 (Windows XP) does not. But this article is on Redirection not Application pools so let's proceed.

Redirection is configured on the Home Directory tab when you are working at the Web Site level.

IIS Supports getting the content from three locations:

  • A directory located on this computer
  • A share located on another computer
  • A redirection to a URL

In this article we are going to focus on the last option - A redirection to a URL

When you click on the option "A redirection to a URL" you get a slightly different looking dialog as shown below (this is a dialog for a Web Site redirection but they basically all look the same except for the tabs displayed).

So far it looks pretty simple - we can redirect to a URL and we have three additional check box options:

  • The exact URL entered above
  • A directory below this one
  • A permanent redirection to this resource

So what do they options mean?

Option 1 - No check box's are checked

When you configure our web site to the following settings (None of the check box's as checked) the following will occur:

Redirect To : www.iisfaq.com

Original URL Requested Redirected URL
www.iisfaq.co.nz www.iisfaq.com
www.iisfaq.co.nz/directory1 www.iisfaq.com/directory1
www.iisfaq.co.nz/directory1/file1.asp www.iisfaq.com/directory1/file1.asp
www.iisfaq.co.nz/directory1/file1.asp?x=10 www.iisfaq.com/directory1/file1.asp

Redirect To : www.iisfaq.com/ChildFolder

Original URL Requested Redirected URL
www.iisfaq.co.nz www.iisfaq.com/ChildFolder
www.iisfaq.co.nz/directory1 www.iisfaq.com/ChildFolder/directory1
www.iisfaq.co.nz/directory1/file1.asp www.iisfaq.com/ChildFolder/directory1/file1.asp
www.iisfaq.co.nz/directory1/file1.asp?x=10 www.iisfaq.com/ChildFolder/directory1/file1.asp

This setting is quite simple - in general IIS replaces the original domain portion of the URL with the value in the Redirect to field. But notice that the last option of each group - the parameter x=10 is missing from the new URL! - see Redirection Variables to help resolve this issue!

Option 2 - The exact URL entered above

The only difference with the first option and this option is that we have checked the box "The exact URL entered above"

Redirect To : www.iisfaq.com

Original URL Requested Redirected URL
www.iisfaq.co.nz www.iisfaq.com
www.iisfaq.co.nz/directory1 www.iisfaq.com
www.iisfaq.co.nz/directory1/file1.asp www.iisfaq.com
www.iisfaq.co.nz/directory1/file1.asp?x=10 www.iisfaq.com

Redirect To : www.iisfaq.com/ChildFolder

Original URL Requested Redirected URL
www.iisfaq.co.nz www.iisfaq.com/ChildFolder
www.iisfaq.co.nz/directory1 www.iisfaq.com/ChildFolder
www.iisfaq.co.nz/directory1/file1.asp www.iisfaq.com/ChildFolder
www.iisfaq.co.nz/directory1/file1.asp?x=10 www.iisfaq.com/ChildFolder

You notice that this time any URL as want to navigate to is redirected to exactly the URL we entered in the Redirect to field.

If you were going to do maintenance on your web site this method is a very good and safe way to redirect users to a maintenance page. No matter what URL they may want to get to they will only be able to get to the URL you specified in the Redirect to field.

Option 3 - A Directory below this one

This option is used to redirect a particular file or folder to another location. If you redirect a folder then only if the folder is requested will this redirection do anything.

Redirect To : /chris.htm    * Note this is a file and not a folder

Original URL Requested Redirected URL
www.iisfaq.co.nz www.iisfaq.co.nz/chris.htm/ (causes a 404 error - notice the extra / at the end of the URL unless you have a directory with that name)
www.iisfaq.co.nz/default.htm www.iisfaq.co.nz/default.htm
www.iisfaq.co.nz/directory1/file1.asp www.iisfaq.co.nz/directory1/file1.asp
www.iisfaq.co.nz/directory1/file1.asp?x=10 www.iisfaq.co.nz/directory1/file1.asp?x=10

Redirect To : /DirectoryX

Original URL Requested Redirected URL
www.iisfaq.co.nz www.iisfaq.co.nz/directoryX/
www.iisfaq.co.nz/?x=10 www.iisfaq.co.nz/directoryX/
www.iisfaq.co.nz/default.htm www.iisfaq.co.nz/default.htm
www.iisfaq.co.nz/directory1/file1.asp www.iisfaq.co.nz/directory1/file1.asp
www.iisfaq.co.nz/directory1/file1.asp?x=10 www.iisfaq.co.nz/directory1/file1.asp?x=10

Redirect To : http://www.iisfaq.com

Original URL Requested Redirected URL
www.iisfaq.co.nz www.iisfaq.com
www.iisfaq.co.nz/?x=10 www.iisfaq.com
www.iisfaq.co.nz/default.htm www.iisfaq.co.nz/default.htm
www.iisfaq.co.nz/directory1/file1.asp www.iisfaq.co.nz/directory1/file1.asp
www.iisfaq.co.nz/directory1/file1.asp?x=10 www.iisfaq.co.nz/directory1/file1.asp?x=10

Redirect To : http://www.iisfaq.com/ChildFolder

Original URL Requested Redirected URL
www.iisfaq.co.nz www.iisfaq.com/ChildFolder
www.iisfaq.co.nz/?x=10 www.iisfaq.com/ChildFolder
www.iisfaq.co.nz/default.htm www.iisfaq.co.nz/default.htm
www.iisfaq.co.nz/directory1/file1.asp www.iisfaq.co.nz/directory1/file1.asp
www.iisfaq.co.nz/directory1/file1.asp?x=10 www.iisfaq.co.nz/directory1/file1.asp?x=10

Option 4 - A Permanent Redirection for this Resource

When this option is checked IIS sends a specific header to the client browser that specifies that this is a permanent redirection to the new resource location. This is done by sending a "301" Permanent Redirect HTTP response. When this option is not checked the redirections are considered temporary, and the client browser receives a "302" Temporary Redirect HTTP response.

Some browsers can use the "301" response code as the signal to permanently change a URL, such as a bookmark.

The following is an example of an HTTP request that is made for a URL

== REQUEST ==================
GET / HTTP/1.0
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*
Accept-Language: en-nz
Cookie: .DOTNETNUKE=60BB2849F975471BDDBF
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 1.0.3705)
Host: www.iisfaq.co.nz
Proxy-Connection: Keep-Alive
== RESPONSE =================
HTTP/1.1 302 Object Moved
Location: http://www.iisfaq.com/forum
Server: Microsoft-IIS/5.1
Content-Type: text/html
Content-Length: 150

From the simple HTTP traffic above we see that since we received a 302 Object Moved HTTP Result code that shows the check box "A permanent redirection for this resource" is not checked.

Here is the same request but this time when "A permanent redirection for this resource" is checked.

== REQUEST ==================
GET / HTTP/1.0
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*
Accept-Language: en-nz
Cookie: .DOTNETNUKE=60BB2849F975471BDDBF
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 1.0.3705)
Host: www.iisfaq.co.nz
Proxy-Connection: Keep-Alive
== RESPONSE =================
HTTP/1.1 301 Error
Location: http://www.iisfaq.com/forum
Server: Microsoft-IIS/5.1
Content-Type: text/html
Content-Length: 150

For more details about HTTP Response Codes see this article : http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

The actual text values Object Moved and Error are returned on IIS 5.1, the actual HTTP status code is the important piece of the result header.

Note: The Location header actually tells the browser where the content can now be located.

Redirect Variables

You can use redirect variables to pass portions of the original URL with the destination URL.

Redirection Variable $P

Passes the parameters in the original URL without the ?

Redirect To : www.iisfaq.com$P

Original URL Requested Redirected URL
www.iisfaq.co.nz www.iisfaq.com
www.iisfaq.co.nz/directory1 www.iisfaq.com/directory1
www.iisfaq.co.nz/directory1/file1.asp www.iisfaq.com/directory1/file1.asp
www.iisfaq.co.nz/directory1/file1.asp?x=10 www.iisfaq.com/directory1/file1.aspx=10

In this case you notice that $P has removed the original "?" from the redirected URL. Why would you want this? Well one reason could be that you want to specify your own parameters in the Redirect to field.

Redirect To : www.iisfaq.com/?Redirect=1&$P

Original URL Requested Redirected URL
www.iisfaq.co.nz www.iisfaq.com/?Redirect=1&
www.iisfaq.co.nz/directory1 www.iisfaq.com/directory1/?Redirect=1&
www.iisfaq.co.nz/directory1/file1.asp www.iisfaq.com/directory1/file1.asp/?Redirect=1&
www.iisfaq.co.nz/directory1/file1.asp?x=10 www.iisfaq.com/directory1/file1.asp/?Redirect=1&x=10

Redirection Variable $Q

Passes the parameters in the original URL including ?

Redirect To : www.iisfaq.com$Q

Original URL Requested Redirected URL
www.iisfaq.co.nz www.iisfaq.com
www.iisfaq.co.nz/directory1 www.iisfaq.com/directory1
www.iisfaq.co.nz/directory1/file1.asp www.iisfaq.com/directory1/file1.asp
www.iisfaq.co.nz/directory1/file1.asp?x=10 www.iisfaq.com/directory1/file1.asp?x=10

Redirection Variable $S

Passes the matched suffix of the requested URL. The matched suffix is the portion of the original URL that remains after the redirected URL is substituted.

In this example we have redirected the folder /Scripts to a new folder /NewScripts

Redirect To : /NewScripts$S

Exact URL Original URL Requested Redirected URL

Not Checked

www.iisfaq.co.nz/Scripts/script.asp www.iisfaq.com/NewScripts/script.asp/script.asp

Not Checked

www.iisfaq.co.nz/Scripts/script.asp?X=10 www.iisfaq.com/NewScripts/script.asp/script.asp

Checked

www.iisfaq.co.nz/Scripts/script.asp www.iisfaq.com/NewScripts/script.asp

Checked

www.iisfaq.co.nz/Scripts/script.asp?X=10 www.iisfaq.com/NewScripts/script.asp

Note: Normally the server will automatically perform this substitution and you normally would only use $S in conjunction with another variable.

Redirection Variable $V

Pass the requested URL without the server name, but not any parameters.

Redirect To : /NewScripts$V

Exact URL Original URL Requested Redirected URL
not checked www.iisfaq.co.nz www.iisfaq.com/NewScripts
not checked www.iisfaq.co.nz/default.htm www.iisfaq.com/NewScripts/default.htm/default.htm
not checked www.iisfaq.co.nz/default.htm?X=10 www.iisfaq.com/NewScripts/default.htm/default.htm
checked www.iisfaq.co.nz www.iisfaq.com/NewScripts
checked www.iisfaq.co.nz/default.htm www.iisfaq.com/NewScripts/default.htm
checked www.iisfaq.co.nz/default.htm?X=10 www.iisfaq.com/NewScripts/default.htm

I will update this document as I get more details and do more testing. I hope that some of these examples will be of use to you in your redirections with IIS.