重写外部子域

时间:2015-11-17 23:34:31

标签: .net azure web-config rewrite

我在azure网站上有一个公共index.html页面:

mysite-production.azurewebsites.net

用户可以设置他们的“页面名称”,以便在您访问时

mysite-production.azurewebsites.net/pagename

显示他们的页面。我正在使用web.config中的重写规则来完成此操作。以下是我目前的两条重写规则:

<rule name="Force HTTPS" enabled="true">
      <match url="(.*)" ignoreCase="false" />
      <conditions>
        <add input="{HTTPS}" pattern="off" />
      </conditions>
      <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
    </rule>
    <rule name="Rewrite to index.html">
      <match url="^([0-9a-z]+)+$" />
      <action type="Rewrite" url="index.html?id={R:1}" />
    </rule>

第一个标准力https,第二个允许我动态加载页面。所以有人去

mysite-production.azurewebsites.net/pagename

他们实际上看到了

mysite-production.azurewebsites.net/index.html?id=pagename

这样我可以使用javascript动态更改索引页面。我还有另一个网址:

mysite.org

我指着天蓝色的网站。我在 mysite.org 上有一个SSL,因为它的清洁用户使用此网站转到他们的自定义页面。一切都很好。

现在问题是我现在有一个第三方需要自己的网址来显示他们的自定义页面。他们有一个独特的自定义页面,我们称之为 custompage ,以便用户可以访问:

mysite.org/custompage

并查看他们的自定义页面。他们的url是一个通配符子域,基本上是这样的:

subdomain.notmysite.org

他们不想要任何重定向。他们只是希望子域显示 mysite.org/custompage ,其子域显示在地址栏中。我创建了cname记录,并且 subdomain.notmysite.org 指向 mysite-production.azurewebsites.net 。所以现在我正在尝试创建一个与 subdomain.notmysite.org 匹配的重写规则,显示他们的自定义页面,但将其网址保留在地址栏中。

这是我试过的其中一个我放在其他两个规则之间的一个:

<rule name="Notmysite" stopProcessing="false">
      <match url=".*" />
      <conditions>
        <add input="{HTTP_HOST}" pattern="^subdomain\.notmysite\.org$"/>
      </conditions>
      <action type="Rewrite" url="{HTTP_HOST}/custompage" />
    </rule>

但我无法弄清楚如何让它发挥作用。

1 个答案:

答案 0 :(得分:0)

能够解决它。问题在于“匹配网址”部分。当我需要检查的是主机上的路径为空时,我正在匹配任何URL。这是工作解决方案。

<rule name="Notmysite" stopProcessing="true">
      <match url="^$" />
      <conditions>
        <add input="{HTTP_HOST}" pattern="^(www.)?subdomain\.notmysite\.org$" />  
      </conditions>
      <action type="Rewrite" url="index.html" />
    </rule>

现在,如果 www.subdomain.notmysite.org subdomain.notmysite.org 访问我的网站会将其重写到索引页面并生成基于内容的内容网址。