如何在IIS中重定向URL路径? [英] How to redirect a URL path in IIS?

查看:276
本文介绍了如何在IIS中重定向URL路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在IIS 6.0中,有一种简单的方法可以将对文件夹的请求重定向到另一个文件夹,同时保留其余路径。



例如



如果我已将内容移至:

mysite.org.uk/stuff

to

stuff.mysite.org.uk /



我可以自动重定向特定页面的请求,例如:
mysite.org.uk/stuff/countrybriefing/tanzania /travel.html

to

stuff.mysite.org.uk/countrybriefing/tanzania/travel.html



I知道.htaccess可以在Apache中做这样的事情,在IIS中是否有相同的东西?

解决方案

取自 Microsoft Technet



在IIS 6.0中重定向网站(IIS 6.0)




浏览器时请求Web站点上的页面或程序Web服务找到URL标识的页面并将其返回给浏览器。当您在网站上移动页面时,您无法始终更正引用该页面旧URL的所有链接。为确保浏览器能够在新URL中找到该页面,您可以指示Web服务器将浏览器重定向到新URL。



您可以重定向文件请求在一个目录中到另一个目录,到另一个Web站点,或到另一个目录中的另一个文件。当浏览器在原始URL处请求文件时,Web服务器会指示浏览器使用新URL请求页面。



重要




您必须是本地计算机上Administrators组的成员才能执行以下过程。作为安全性最佳操作,请使用不在Administrators组中的帐户登录计算机,然后使用runas命令以管理员身份运行IIS管理器。在命令提示符处,键入runas / user:Administrative_AccountNamemmc%systemroot%\system32 \inetsrv \ iis.msc。




程序



将请求重定向到另一个网站或目录



  1. 在IIS管理器中,展开本地计算机,右键单击要重定向的网站或目录,然后单击属性。


  2. 单击主目录,虚拟目录或目录选项卡。


  3. 在此源的内容应来自,单击重定向到URL。


  4. 在重定向中在框中,键入目标目录或网站的URL。例如,要将Catalog目录中文件的所有请求重定向到NewCatalog目录,请键入/ NewCatalog。


将所有请求重定向到单个文件



  1. 在IIS管理器中,展开本地计算机,右键单击要重定向的网站或目录,然后单击属性。


  2. 单击主目录,虚拟目录或目录选项卡。


  3. 在此源的内容应来自下,单击重定向到URL。


  4. 在重定向到框中,键入目标的URL文件。


  5. 选中上面输入的确切URL复选框,以防止Web服务器将原始文件名附加到目标URL。



    您可以在目标网址中使用通配符和重定向变量来精确控制原始网址转换为目标网址的方式。



    您还可以使用重定向方法将特定目录中文件的所有请求重定向到程序。通常,您应该将原始URL中的任何参数传递给程序,您可以使用重定向变量来执行此操作。


    将请求重定向到程序



  6. 在IIS管理器中,展开本地计算机,右键单击要重定向的网站或目录,然后单击属性。


  7. 单击主目录,虚拟目录或目录选项卡。


  8. 在此源的内容应来自,单击重定向到URL。



    在重定向到框中,键入程序的URL,包括将参数传递给程序所需的任何重定向变量。例如,要将Scripts目录中脚本的所有请求重定向到记录请求的URL和使用URL传递的任何参数的日志记录程序,请键入/Scripts/Logger.exe?URL=$V+PARAMS=$P。 $ V和$ P是重定向变量。


  9. 选中上面输入的确切URL复选框以防止Web服务器将原始文件名附加到目标网址。



In IIS 6.0, is there an easy way to re-direct requests to a folder to another folder, while preserving the rest of the path.

e.g.

If I have moved the content from:
mysite.org.uk/stuff
to
stuff.mysite.org.uk/

Can I automatically redirect requests for specific pages like
mysite.org.uk/stuff/countrybriefing/tanzania/travel.html
to
stuff.mysite.org.uk/countrybriefing/tanzania/travel.html

I know that .htaccess can do things like this in Apache, is there an equivalent in IIS?

解决方案

Taken from Microsoft Technet.

Redirecting Web Sites in IIS 6.0 (IIS 6.0)


When a browser requests a page or program on your Web site, the Web server locates the page identified by the URL and returns it to the browser. When you move a page on your Web site, you can't always correct all of the links that refer to the old URL of the page. To make sure that browsers can find the page at the new URL, you can instruct the Web server to redirect the browser to the new URL.

You can redirect requests for files in one directory to a different directory, to a different Web site, or to another file in a different directory. When the browser requests the file at the original URL, the Web server instructs the browser to request the page by using the new URL.

Important

You must be a member of the Administrators group on the local computer to perform the following procedure or procedures. As a security best practice, log on to your computer by using an account that is not in the Administrators group, and then use the runas command to run IIS Manager as an administrator. At a command prompt, type runas /user:Administrative_AccountName "mmc %systemroot%\system32\inetsrv\iis.msc".

Procedures

To redirect requests to another Web site or directory


  1. In IIS Manager, expand the local computer, right-click the Web site or directory you want to redirect, and click Properties.

  2. Click the Home Directory, Virtual Directory, or Directory tab.

  3. Under The content for this source should come from, click A redirection to a URL.

  4. In the Redirect to box, type the URL of the destination directory or Web site. For example, to redirect all requests for files in the Catalog directory to the NewCatalog directory, type /NewCatalog.

To redirect all requests to a single file


  1. In IIS Manager, expand the local computer, right-click the Web site or directory you want to redirect, and click Properties.

  2. Click the Home Directory, Virtual Directory, or Directory tab.

  3. Under The content for this source should come from, click A redirection to a URL.

  4. In the Redirect to box, type the URL of the destination file.

  5. Select the The exact URL entered above check box to prevent the Web server from appending the original file name to the destination URL.

    You can use wildcards and redirect variables in the destination URL to precisely control how the original URL is translated into the destination URL.

    You can also use the redirect method to redirect all requests for files in a particular directory to a program. Generally, you should pass any parameters from the original URL to the program, which you can do by using redirect variables.

    To redirect requests to a program


  6. In IIS Manager, expand the local computer, right-click the Web site or directory you want to redirect, and click Properties.

  7. Click the Home Directory, Virtual Directory, or Directory tab.

  8. Under The content for this source should come from, click A redirection to a URL.

    In the Redirect to box, type the URL of the program, including any redirect variables needed to pass parameters to the program. For example, to redirect all requests for scripts in a Scripts directory to a logging program that records the requested URL and any parameters passed with the URL, type /Scripts/Logger.exe?URL=$V+PARAMS=$P. $V and $P are redirect variables.

  9. Select the The exact URL entered above check box to prevent the Web server from appending the original file name to the destination URL.

这篇关于如何在IIS中重定向URL路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆