Redirection

Sometimes when you are managing a website, you may need to move content to some other location to reorganize your site or for some other purpose. As a result, clients who try to access this content using URLs saved in their Favorites folder will receive “HTTP 404—File Not Found.” Fortunately, you can use redirection to prevent such errors. Redirection is a way of having IIS tell web browsers that the content they are requesting has moved to a different location by having IIS provide the browser with the new URL for the moved content. The browser responds by automatically trying to open the new location without any intervention by the user.

There are several ways you can redirect client requests for files in a directory on your web server. For example, you can redirect such requests:

  • To a different directory on the same site to which the content has been moved. In this case, all requests such as http://site/olddir/anyfile.abc will be redirected to http://site/newdir/anyfile.abc, regardless of the name of the file requested.

  • To an entirely different website to which the content has been moved. In this case, all requests such as http://site/olddir/anyfile.abc will be redirected to http://othersite/anyfile.abc for any filename.

  • To go to a specific file in any directory on the site, for example, a file that displays the message “We’re reorganizing our site, please come back soon,” no matter what page is requested. In this case, all requests such as http://site/olddir/anyfile.abc will be redirected to http://site/otherdir/message.htm, regardless of what file is requested.

  • To go to a specific URL that can be anything on any site on the Internet. In this case, all requests such as http://site/olddir/anyfile.abc will be redirected to http://redirect_URL, regardless of what file is requested.

Configuring Redirection

To configure redirection for a website or virtual directory, open the properties sheet for that site or directory and select the Home Directory or Virtual Directory tab. For example, you can redirect requests to content in the root of the Default Web Site to a specific page message.htm in the root of the Test website created earlier. To do this, first use Notepad to create a file named message.htm that has a short message in it, and then save this file in the C:\ folder on the IIS machine. Now do the following:

  1. Open the properties sheet for the Default Web Site in IIS Manager and select the Home Directory tab.

  2. Select the option A Redirection to a URL.

  3. The Home Directory tab now changes to display redirection settings (Figure 16-15).

    click to expand
    Figure 16-15: Configuring redirection

  4. Select the check box labeled The Exact URL Entered Above, and type http://IP_address/message.htm, where IP_address is the address for the Test website on the IIS machine.

  5. Click OK to close the properties sheet and apply the changes.

  6. Now right-click the Default Web Site in IIS Manager and select Browse, and the message.htm file should be displayed in the results pane.

Other things you can try:

  • Redirect the root directory on your Default Web Site to http://www.yahoo .com/index.html (redirection to a page on the Internet).

  • Move the content from your Default Web Site to your Test site, leave the check box The Exact URL Entered Above selected, and type http://IP_address, where IP_address is the address for the Test website on the IIS machine. This should redirect a request for anyfile.abc in the root of the Default Web Site to anyfile.abc in the root of the Test website.

  • Select the check box A Directory Below URL Entered to Redirect Requests to the Root Directory of the Site to Virtual Directory Beneath It. For example, if you move the content of the Test website to the Temp virtual directory below it, you can type \Temp in the Redirect To text box to accomplish the redirection.

  • Select the check box A Permanent Redirection for This Resource to indicate that the content has been moved permanently, and not temporarily. Doing this changes the HTTP status message IIS sends during redirection from “HTTP 302—Temporary Redirect” to “HTTP 301—Permanent Redirect.” If supported, when your web browser receives this message, it will update any favorite or bookmark associated with its request so that next time the user opens it, the browser will open the new URL and no redirection will occur.

    Tip 

    You can also configure redirection on FTP sites, virtual directories, and files.




IIS 6 Administration
IIS 6 Administration
ISBN: 0072194855
EAN: 2147483647
Year: 2003
Pages: 131
Authors: Mitch Tulloch

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net