【问题标题】:azure web app : www to non www https天蓝色网络应用程序:www 到非 www https
【发布时间】:2017-08-04 09:56:57
【问题描述】:

我有一个 Azure Web 应用程序,需要帮助执行 https。

https://www.example.comhttps://example.com

http://www.example.comhttps://example.com

www.example.com 到https://example.com

example.com 到https://example.com

当前的web.config如下。这不适用于https://www.example.com -> https://example.com

<rules>


        <!-- Force HTTPS for all requests -->
        <rule name="HTTPS" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
          <match url="*" />
          <conditions>
            <add input="{HTTPS}" pattern="off" />
          </conditions>
          <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" />
        </rule>


        <!-- Redirect all requests to non www-->
        <rule name="WWW" stopProcessing="true">
          <match url="^(.*)$" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" />
          </conditions>
          <action type="Redirect" url="https://example.com{PATH_INFO}" />
        </rule>

</rules>

【问题讨论】:

    标签: iis web-config azure-web-app-service iis-8


    【解决方案1】:

    根据你的url重写规则,我假设你的规则没有问题。虽然我没有配置自定义域,但我只是在我的 azure web 应用程序上测试它,它只包含一些静态 html 文件和 web.config 文件,然后我强制它从bruce-webapp.azurewebsites.net 重定向到https://azurewebsites.net,如下所示:

    <rule name="Remove www" stopProcessing="true">
       <match url="^(.*)$" />
       <conditions>
          <add input="{HTTP_HOST}" pattern="^(bruce-webapp\.)(.*)$" />
       </conditions>
       <action type="Redirect" url="https://azurewebsites.net{PATH_INFO}"/>
    </rule>
    

    另外,请使用以下规则删除 www 前缀以缩小此问题:

    <rule name="Remove WWW prefix" stopProcessing="true">
        <match url="(.*)" ignoreCase="true" />
        <conditions>
           <add input="{HTTP_HOST}" pattern="^www\.yourdomain\.com$" />
        </conditions>
        <action type="Redirect" url="https://yourdomain.com/{R:1}" redirectType="Permanent" />
    </rule>
    

    如果上述试验仍然无法解决您的问题,您可以利用fiddler 收集网络跟踪来解决此问题。此外,您可以使用更多详细信息(提琴手网络跟踪或通过浏览器浏览时发生的情况)更新您的问题,以便我们找到此问题。

    【讨论】:

    • 感谢您的回答,目前我已切换到 www 格式。
    【解决方案2】:

    您可以使用两个单独的规则来做到这一点。在您的 web.config 文件中设置以下配置。

    <rewrite>
        <rules>
            <rule name="HTTP Redirect to HTTPS" enabled="true" stopProcessing="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>
        </rules>
    </rewrite>
    
        <rewrite>
        <rules>
            <rule name="Redirects to www.domain.com" patternSyntax="ECMAScript" stopProcessing="true">
                <match url=".*" />
                <conditions logicalGrouping="MatchAny">
                    <add input="{HTTP_HOST}" pattern="^domain.com$" />
                </conditions>
                <action type="Redirect" url="https://example.com/{R:0}" />
            </rule>
        </rules>
    
    </rewrite>
    

    希望这会有所帮助。

    【讨论】:

    • 这不适用于 https://www.example.com" 到 https://example.com"
    猜你喜欢
    • 1970-01-01
    • 2014-12-16
    • 2019-04-19
    • 1970-01-01
    • 2012-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-06
    相关资源
    最近更新 更多