【问题标题】:Can an Azure App Service redirect www to non-www?Azure 应用服务能否将 www 重定向到非 www?
【发布时间】:2023-01-30 17:03:43
【问题描述】:
是否可以在 Azure 应用程序服务级别将 www 重定向到非 www?
我在应用程序服务级别而不是在我的应用程序的配置文件中需要它。我已经能够让 http 到 https 在 tls/ssl 刀片下工作,但我没有看到重定向 www 的方法。
我是否需要其他资源,如前门或应用程序管理器?我想在应用程序服务本身中处理它。
我的应用程序服务器正在运行一个使用 nginx 服务器的 docker 容器。我不是 nginx 的专家,也无法让重定向在 nginx 配置中工作。另外,我想在我的二头肌文件中设置它。
【问题讨论】:
标签:
azure-web-app-service
【解决方案1】:
要重写 URL,您需要在 wwwroot 文件夹中创建一个 web.config 文件并将必要的条目放入其中(如果您的站点还没有 web.config 文件)。
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect requests to default azure websites domain" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^yoursite.azurewebsites.net$" />
</conditions>
<action type="Redirect" url="http://yoursite.com/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
原回答:https://learn.microsoft.com/en-us/answers/questions/193377/how-to-redirect-in-app-service