【问题标题】:How to URL Redirect "www.example1.com" & "www.example2.com" & "example2.com" to "example1.com" in IIS7如何在 IIS7 中将“www.example1.com”和“www.example2.com”和“example2.com”URL 重定向到“example1.com”
【发布时间】:2012-03-19 03:28:54
【问题描述】:

我们在将 4 个 URL 重定向到单个 URL 时遇到问题。

以下是我们需要的映射。

输入的 URL -> 目标 URL
示例 1.com -> 示例 1.com
www.example1.com -> example1.com
example2.com -> example1.com
www.example2.com -> example1.com

我们在 WIn Srv 2008 SP1 上使用 IIS7。

我们现在在 IIS 中设置了所有绑定。我们有 HTTPS。但对于目标 URL 选项,我们只有一个有效的证书。所有其余选项都显示为“此连接不受信任”,用户必须手动单击继续访问网站。即使用户键入任何 URL,我们也希望将用户重定向到所需的站点。我的意思是浏览器中的用户 URL 应该更改为目标 URL,并且应该打开安全连接。

我在谷歌搜索后找到了 URL Redirect 2.0。这会解决我的问题吗。是否安全或有任何问题。

无需安装任何更好的选择。

TIA

阿伦·库马尔·阿卢。

【问题讨论】:

  • 如果您的要求是在用户输入上述任何 URL 时访问同一个 Web,您只需将它们全部添加到服务器绑定下的同一个站点即可。打开 IIS 控制台 > 右键单击​​您的网站 > 单击编辑绑定 > 在站点绑定框中 > 全部添加。
  • Thanx Indikaf,我们已经拥有了,但仅对于所需的选项,我们拥有有效的证书。所有其余选项都显示为“此连接不受信任”,用户必须手动单击继续访问网站。即使用户键入任何 URL,我们也希望将用户重定向到所需的站点
  • iis.net/ConfigReference/system.webServer/httpRedirect。这给出了如何在请求到达后使用 iis 执行此操作,但正如您所说,如果它不受信任,我认为您需要在请求到达您的 Web 服务器之前执行此操作。
  • 我试过了,但我猜它陷入了一个循环,直到我做了一个 iisreset,网页才打开,然后网站用目标 URL 打开。所以我打算使用 URL Redirect 2.0 为其他 3 进行正则表达式匹配并将其重定向到 tarhet URL。第一次做这个 IIS 重定向,所以甚至不知道这是否对我有用。甚至需要我的前辈 b4 安装 IIS 插件时发出继续信号。这对我有用吗?任何想法。

标签: iis-7 url-rewriting redirect


【解决方案1】:

我假设你已经安装了 IIS “URL Rewrite”模块,如果是,那么使用这些重写规则:

<rule name="AllToExample1Http" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^www\.example1\.com$|^example2\.com$|^www\.example2\.com$" />
        <add input="{HTTPS}" pattern="^OFF$" />
    </conditions>
    <action type="Redirect" url="http://example1.com/{R:1}" />
</rule>
<rule name="AllToExample1Https" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^www\.example1\.com$|^example2\.com$|^www\.example2\.com$" />
        <add input="{HTTPS}" pattern="^ON$" />
    </conditions>
    <action type="Redirect" url="https://example1.com/{R:1}" />
</rule>

【讨论】:

  • Thanx Tomek,你能帮我看看动作标签中的这个“{R:1}”是什么吗?以下对我来说很好,但在 3-4 小时后,子站点在我执行 iisreset 之后才会打开,然后它就可以工作了。
  • example1.com{R:1}" redirectType="Permanent" />
  • 现在我已将其更改为 "example1.com{R:0}" >" 现在它似乎工作正常,但我不确定如果这是适当的解决方案,我自己。请确认。 TIA。
  • 您所做的更改将起作用,前提是:1. 您打算重定向任何不是 example1.com 的域 2. 请求不包含 path 部分,如果你最终会重定向到http://example1.comYourPath(注意主机名后面缺少斜杠),{R:0} 在这种特殊情况下相当于{R:1}
【解决方案2】:

<configuration> <system.webServer> <defaultDocument> <files> <clear /> <add value="index.html" /> <add value="maintenance.htm" /> <add value="index.htm" /> <add value="Default.htm" /> <add value="Default.asp" /> <add value="iisstart.htm" /> <add value="default.aspx" /> </files> </defaultDocument> <httpRedirect enabled="false" destination="" exactDestination="false" /> <rewrite> <rules> <rule name="CanonicalHostNameRule1" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTP_HOST}" pattern="^example1\.com$" negate="true" /> </conditions> <action type="Redirect" url="http://example1.com/{R:0}"/> </rule> </rules> </rewrite> </system.webServer> </configuration>

【讨论】:

  • 感谢every1 的帮助。这确实解决了我的问题。所需的配置已经完成,将所有 http 请求转换为 https 请求。
猜你喜欢
  • 2017-04-21
  • 2019-08-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多