【问题标题】:Point a domain to a URI of an IIS 7 website without changing the domain将域指向 IIS 7 网站的 URI,而不更改域
【发布时间】:2013-06-04 02:55:56
【问题描述】:

我已经在 IIS 7 中为具有 2 个绑定的特定站点设置了 URL 重写。

  1. main.mydomain.com
  2. hub.mydomain.com

我还应用了如下所示的 URL 重写规则:

匹配(.*) 接着 条件下 其中{HTTP_HOST} 匹配^hub\.mydomain\.com$

301 重定向到

http://main.mydomain.com/hub/home.html

这行得通,目的是让hub.mydomain.com 将用户定向到http://main.mydomain.com/hub/home.html 的URI

我现在被要求更改此设置,以便 hub.mydomain.com 保留在用户的浏览器地址中,但显示正确的 /hub/home.html 内容。

如何做到这一点?我想顾名思义,URL Rewrite 不再合适了?如果是这样,我还能怎么做?

编辑:

main.mydomain.com还是要到网站根目录下。

【问题讨论】:

  • 您不能将 IIS 中网站的默认页面设置为 /hub/home.html。然后,无论他们浏览到http;//main.mydomain.com 还是http://hub.mydomain.com,浏览器都会显示位于相对路径/hub/home.html 的页面,因为这两个域都映射到IIS 中的那个站点。
  • 对不起,我没有提到我仍然希望main.mydomain.com 去网站的主页。

标签: iis url-rewriting


【解决方案1】:

在您的问题中,您声明 main.mydomain.comhub.mydomain.com 绑定到一个网站。

所以如果你想让点击hub.mydomain.com的用户看到来自http://main.mydomain.com/hub/home.html的内容,就相当于让他们点击hub.mydomain.com并获得来自http://hub.mydomain.com/hub/home.html的内容。

你的规则会这样:

<rule name="hub rewrite">
    <match url="^/?$" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^hub\.mydomain\.com$" />
    </conditions>
    <action type="Rewrite" url="hub/home.html" />
</rule>

【讨论】:

  • 感谢您的建议,掌心时刻。这里的关键是使用重写而不是重定向和相对路径。好东西。出于兴趣,我使用了站点菜单上的 IIS7 Url Rewrite 功能。这个 xml 应用在哪里?
  • 它应用于web.config,在&lt;configuration&gt;&lt;system.webServer&gt;&lt;/system.webServer&gt;&lt;/configuration&gt; 部分内。很高兴它有帮助!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-08-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-28
  • 1970-01-01
  • 2017-03-23
相关资源
最近更新 更多