【问题标题】:URL rewrite of an multitenant application using IIS使用 IIS 重写多租户应用程序的 URL
【发布时间】:2021-10-15 12:07:03
【问题描述】:

对于多租户应用程序,我想通过 URL 重写 功能将带有 www 的 URL 重定向到非 www URL。
我在 web.config 文件中添加了几个规则,如下所示。

   <rule name="Redirect to non www main domain" stopProcessing="true">
        <match url="(.*)" />
        <conditions trackAllCaptures="false">
            <add input="{HTTP_HOST}" pattern="www.test.com" />
        </conditions>
        <action type="Redirect" url="https://test.com/{R:1}" />
    </rule>
    
    <rule name="Force non-WWW" enabled="true" stopProcessing="true">
        <match url="(.*)" />
        <conditions logicalGrouping="MatchAny">
            <add input="{HTTP_HOST}" pattern="(www\.)(.*)$" />
        </conditions>
        <action type="Redirect" url="https://{C:2}/{R:1}" appendQueryString="true" />
    </rule>
    
    <rule name="Force HTTPS" enabled="true" stopProcessing="true">
        <match url="(.*)" />
        <conditions logicalGrouping="MatchAny">
            <add input="{HTTPS}" pattern="off" />
        </conditions>
        <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" />
    </rule>

这些规则涵盖了所有场景,除了子域的一种场景。

http://subdomain.tezt1.com ==> https://subdomain.tezt1.com (OK)
http://www.subdomain.tezt1.com ==> https://subdomain.tezt1.com (OK)
www.subdomain.tezt1.com ==> https://subdomain.tezt1.com (OK)
@987654327 @ ==> https://subdomain.tezt1.com (OK)
https://www.subdomain.tezt1.com ==> (NOT OK) [期望 - https://subdomain.tezt1.com]

这可能是什么问题?

【问题讨论】:

标签: asp.net-mvc iis url-rewriting iis-7 iis-7.5


【解决方案1】:

如果你想去掉www,你可以试试这个规则:

<rule name="Remove WWW" stopProcessing="true">
   <match url=".*" ignoreCase="true" />
     <conditions logicalGrouping="MatchAll">
       <add input="{HTTP_HOST}" pattern="^www\.(.*)$" />
     </conditions>
   <action type="Redirect" url="http://{C:1}/{R:0}" appendQueryString="true" redirectType="Permanent" />
</rule>

【讨论】:

  • 感谢您的回复,是的,我已经完成了与您提到的相同的事情,并且我设法从 URL 中删除了 www。但我担心的是请求何时使用 SSL (https)。它不工作。
  • 大家可以试试,有问题可以来讨论。
猜你喜欢
  • 2014-05-06
  • 1970-01-01
  • 1970-01-01
  • 2015-09-11
  • 2021-06-06
  • 1970-01-01
  • 1970-01-01
  • 2018-08-29
  • 2011-05-05
相关资源
最近更新 更多