asp.net - Azure 将非 www 重定向到 www
问题描述
我对 Azure 重定向有疑问。
我搜索了其他主题,但不是我的问题。
我为此配置了 ASP.NET Core 2.2 项目和 Azure。我也有指向 Azure 的域。我已将 www.example.com 格式的域添加到 azure,它也适用于 https。
example.com 格式出现问题
我想将 example.com 格式重定向到 www.example.com URL
我设法用这个来完成这项工作,但时间很短。我使用这个 web.config 进行重定向
网络配置
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<rewrite>
<rules>
<rule name="CanonicalHostNameRule" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^example.com$" />
</conditions>
<action type="Redirect" url="https://www.example.com/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
奇怪的是 Google Chrome 和 Opera 重定向到 www 域,而不是 Edge 和 Firefox。然后当我清除缓存时,它不会重定向。
似乎 Azure 喜欢重写一些东西。
感谢帮助!!
解决方案
除了 web.config 文件更改之外,请确保 Azure 网站实例包含该区域内的正确域绑定Hostname bindings
。
<rule name="Redirect to www">
<match url=".*" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^example.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:0}" redirectType="Permanent"/>
</rule>
推荐阅读
- android - 如何开发可与旧版 Google Play 服务用于 AR 的 ARCore 应用程序?
- python - Pytorch 内存分析器为空返回高 CPU 内存
- javascript - Vue staging build 创建一个开发版本而不是生产版本
- c++ - 无法在 CMake 中设置 c++ 版本
- c++ - 试图为wallhack usw写一个DLL
- excel - VBA - 后期绑定 Outlook.Mailitem 以支持不同的 Excel 版本
- c# - 您是否应该为 Web 应用程序/API 提供一个 HTTP 客户端?
- c# - 如何获得 TimePicker 的值?
- javascript - Javascript打印功能打破下拉表单提交更改
- python - 使用 nltk 和 word net 将单词从过去时变为将来时