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

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

问题描述

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

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.

例如

如果我已将内容从:
mysite.org.uk/stuff

stuff.mysite.org.uk/

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

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

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

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

我知道 .htaccess 可以在 Apache 中做这样的事情,在 IIS 中是否有等价物?

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

推荐答案

摘自 微软技术网.

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


当浏览器请求您网站上的页面或程序时,Web 服务器会定位由 URL 标识的页面并将其返回给浏览器.当您在网站上移动页面时,您不能总是更正指向页面旧 URL 的所有链接.为确保浏览器可以在新 URL 处找到页面,您可以指示 Web 服务器将浏览器重定向到新 URL.

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.

您可以将对一个目录中的文件的请求重定向到另一个目录、另一个网站或另一个目录中的另一个文件.当浏览器请求原始 URL 处的文件时,Web 服务器指示浏览器使用新 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

您必须是本地计算机上管理员组的成员才能执行以下一个或多个过程.作为安全最佳做法,请使用不在 Administrators 组中的帐户登录到您的计算机,然后使用 runas 命令以管理员身份运行 IIS 管理器.在命令提示符下,键入 runas/user:Administrative_AccountName "mmc %systemroot%system32inetsrviis.msc".

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%system32inetsrviis.msc".

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


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

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

单击主目录、虚拟目录或目录选项卡.

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

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

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

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

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.

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


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

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

单击主目录、虚拟目录或目录选项卡.

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

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

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

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

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

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

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.

您还可以使用重定向方法将特定目录中的所有文件请求重定向到程序.通常,您应该将原始 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


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

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

单击主目录、虚拟目录或目录选项卡.

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

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

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

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

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.

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

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天全站免登陆