How to redirect URLs to different Web sites

http://support.microsoft.com/kb/324000

This article describes how to translate redirection and rewriting configurations from an Apache configuration file to Internet Information Services (IIS).

Redirecting URLs

loadTOCNode(2, 'summary'); When you use Apache, you can redirect URLs by using the Redirect directive to point a folder or a location to a different folder on either the same Web site or a different Web site. You can also alias a folder to another location by using the Alias directive. If you use IIS, you can perform the same tasks by using the URL Redirection functionality.

To redirect a folder or file IIS:

  1. Log on to the Web server computer as an administrator.
  2. Click Start , point to Settings , and then click Control Panel .
  3. Double-click Administrative Tools , and then double click Internet Services Manager .
  4. Right-click the Web site or the folder, and then click Open .
  5. Right-click the folder display, point to New , and then click Folder .
  6. Return to Internet Services Manager.
  7. Right-click the folder that you just created, and then click Properties .
  8. Click the Directory tab, and then click A redirection to a URL .
  9. To redirect the folder to another URL, click the URL of the folder or the Web site that is described in step 4, and then type the complete URL to the new site in the Redirect to box.
  10. To redirect the folder to another folder within in this folder (for example, Projects to Sections/Departments/Projects), click A directory below this one , and then type the new folder in the Redirect to box.
  11. To mark the redirection type as a permanent redirection (and not a temporary redirection), click A permanent redirection for this resource .

    If you use this setting, bookmarks and other details are automatically updated on some browsers.
  12. Click OK to save the changes.

Rewriting URLs

loadTOCNode(2, 'summary'); If you use Apache, you can use the regular expression system to rewrite or redirect URLs to different folders, files, or directories. If you are using IIS, you can perform the same task by using a combination of wildcard characters and replacement variables. See the following table to determine the elements of a URL that you can substitute during a rewriting procedure.

Collapse this table Expand this table
Variable Description Example
$S Passes the last matched
element from a URL.
If /scripts is redirected to /newscripts and
the original request is for /scripts/program.exe,
/program.exe is the suffix. The server
automatically performs this suffix substitution.
You use the $S variable
only in combination with other variables.
$P Passes the parameters
in the original URL.
For example, if the original URL is
/scripts/myscript.asp?number=1,
the string "number=1"
is mapped into the destination URL.
$Q Used like $P, but includes
a leading question mark.
For example, if the original URL is
/scripts/myscript.asp?number=1,
the string "?number=1"
is mapped into the destination URL.
$V Passes the requested URL,
without the server name.
For example, if the original URL is
//myserver/scripts/myscript.asp,
the string "/scripts/myscript.asp"
is mapped into the destination URL.
$0
through
$9
Passes the portion
of the requested URL that
matches the indicated wildcard character.
! Do not redirect. Use this variable to prevent redirecting a
subfolder or an individual file in a
virtual directory that has been redirected.


IIS supports the following wildcard characters:

  • Asterisk (*): The wildcard character for any character
  • Question mark (?): The wildcard character for a single character.

You use the redirection functionality described earlier in this article to activate the rewriting. Make sure that the Redirect to box contains the source and the destination URL, separated by a semicolon (;).

For example, to redirect all the files that end with .html to the Default.html file:

  1. Right-click the folder that you want to use as the base for rewriting, and then click Properties .
  2. Click the Directory tab.
  3. Click A redirection to a URL .
  4. Click the exact URL of the folder that is described in step 1.
  5. Type *.html;default.html in the Redirect to box.
  6. Click OK to accept the changes.

To redirect the query for a script to a different script, for example, to redirect myscript.asp?number=1 to newscript.asp?number=1:

  1. Right-click on the original script, and then click Properties .
  2. Click the File tab.
  3. Click A redirection to a URL .
  4. Click the exact URL of the script that is described in step 1.
  5. Type newscript.asp$Q in the Redirect to box.
  6. Click OK to accept the changes.

你可能感兴趣的:(apache,Web,Microsoft,asp,IIS)