azure web应用程序:www到非www https
我有一个Azure Web应用程序,需要有关强制执行https的帮助。azure web应用程序:www到非www https
https://www.example.com到https://example.com
http://www.example.com到https://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>
根据你的url重写规则,我认为你的规则没有问题。虽然我不配置自定义域,我只是测试它刚刚包含一些静态的HTML文件和web.config文件我蔚蓝的web应用程序,然后我强迫它从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到收集网络跟踪来解决这个问题。此外,您可以使用更多详细信息更新您的问题(小提琴手网络痕迹或当您通过浏览器浏览它时发生了什么),以便我们找到此问题。
你可以用两个单独的规则做到这一点。在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” – nitin
感谢您的答案,现在,我已切换到www格式。 – nitin
看来你已经解决了它。如果我的答案可以帮助你,请将其标记为可接受的答案。 –
标记可以接受,谢谢 – nitin