||Internet Information Server (1) blog.crowe.co.nz.Models.Category
Internet Information Server
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?
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.
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:
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:
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:
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
Redirect To : www.iisfaq.com/ChildFolder
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
Redirect To : 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
Redirect To : /DirectoryX
Redirect To : http://www.iisfaq.com
Redirect To : http://www.iisfaq.com/ChildFolder
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
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.
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.
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
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
Redirection Variable $Q
Passes the parameters in the original URL including ?
Redirect To : www.iisfaq.com$Q
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
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
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.