Subscribe to Windows IT Pro
August 13, 2000 12:00 AM

IIS 101: Redirection

Windows IT Pro
InstantDoc ID #9743
Rating: (0)

Editor’s Note: Each month, this Web-exclusive column provides resources and answers for new IIS administrators. For more information about beginning IIS administration, be sure to check out Brett Hill’s IIS Answers (http://www.IISAnswers.com).

Redirection is the main trick magicians use to perform sleight of hand: If you’re looking somewhere else, you don’t notice what they’re doing. With IIS, you can do your own bit of magic, redirecting users anywhere you want based on the criteria you choose. Several methods for redirection exist; this month, I talk briefly about three methods—built-in redirection, redirection through Active Server Pages (ASP), and redirection through an Internet Server API (ISAPI) filter.

Method 1: Using Built-in Redirection
IIS lets you specify where you want to relocate the content for a Web site or virtual directory. You specify this location on the Home Directory tab, which Figure 1 shows, for a Web site or on the Virtual Directory tab for a virtual directory. To access these tabs, right-click the Web site (or virtual directory) in Microsoft Management Console (MMC) and select Properties. When the Properties dialog box appears, click the Home Directory (or Virtual Directory) tab.

One choice is A redirection to a URL. To relocate content to a URL, enter the http:// path to the redirection and select The exact URL entered above check box. (You can use the same technique on the file’s properties within MMC to redirect an individual file as opposed to an entire Web site or virtual directory.) When you click OK or Apply, you set the redirection. You might need to stop and start the Web site for the redirection to take effect.

If you’re experienced in using built-in redirection, you might want to check out the online IIS documentation about redirection for information about using variables (e.g., $S, $P, $Q, $V, $1-9, !) in your redirection path. Variables let you perform some rather advanced manipulation without programming. For example, you can route http://server1.com?name=John&action=1 to http://server2.com/newfolder?name=John&action=1&redirect="yes". For details about the redirection variables, see the IIS online documentation.

Method 2: Using ASP
The built-in redirection variables referenced above give you a lot of control, but sometimes you need even more. With ASP, the extra control comes from the built-in Redirect method.

The Redirect method lets you create a page that will route users to the proper location based on the criteria you specify. Examples of ways to use this method include

  • Routing users to pages optimized for their browser
  • Routing users to a location based on group membership
  • Routing users to the proper information based on their completing a form
  • Automatically routing users back to a page to complete a transaction
  • Routing users to a page that is in the language they use

Here’s an example of the code to accomplish this type of redirection:

<% Response.Redirect = ("http://targetserver.com/newpage.htm) %>

To use this code, you need to enter your target URL in place of the example URL.

Clearly, there’s more to this process than I can go into here. I just want to introduce you to the idea. You need to know a few things about ASP to use this technique; a good place to start is the LearnASP Web site (http://www.learnasp.com).

Method 3: ISAPI Filters
An ISAPI filter is a program through which IIS can pass all incoming and outgoing data. The program can act on that data and insert, route, or do whatever you want to it. Secure Sockets Layer (SSL) is an example of an ISAPI filter.

Writing such a filter isn’t something you can do on a whim; it requires expert knowledge of C++ and the ISAPI specifications. I mention the option here because if you often redirect users, this method provides the best performance. Redirection is a costly process in terms of time and overhead, so for some sites, an ISAPI filter is the best solution.

Next Month
You can use other methods for achieving redirection, but these three methods can accomplish most of what you would hope to do in the normal course of operations. Next month, I’ll explore the many ways in which you can use virtual directories to make your Web structure more flexible and secure.

Related Content:

ARTICLE TOOLS

Comments
  • Mauricio Foster
    10 years ago
    Nov 04, 2002

    I would like to setup a link www.xxx.com/blahblah where blabla is a separate web site on the same machine from where www.xxx.com is hosted.

    I'd like it appear invisible to the user ie. they wouldn't notice that they were being redirected.

    So if the user types in www.xxx.com/blahblah then actually get served up content from www.ZZZ.com/thisurl/thaturl.

    What they actually see in their browser though is www.xxx.com/blahblah

    Can this be done and if so how?

  • Eric Hayslett
    10 years ago
    Jan 16, 2002

    I had a problem when trying to use the redirect you gave
    <% Response.Redirect = "http://targetserver.com/newpage.htm) %>

    by taking the "=" out of the line I got it to work, I found out about the = from the microsoft site http://msdn.microsoft.com/library/default.asp?URL=/library/periodic/period00/redir.htm

    Just thought I might help some people if they are getting an error with their redirect function

    Cheers
    Eric

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.