【发布时间】:2020-05-29 07:56:54
【问题描述】:
我正在尝试在 Asp.Net 项目中设置重写规则。
重写为 https 并删除任何 "www." 目前在生产中有效,但是当我尝试在 localhost 上运行它时,它不断将其重定向到 https。
这是一个在 Azure 上运行的 Umbraco 站点。这就是为什么存在第一条规则的原因。
这是它目前的样子: 我有一个规则和两个条件试图跳过 localhost 的重定向,但它们都不起作用。
<system.webServer>
<rewrite>
<rules>
<rule name="AlwaysOn agent requests without any redirections" stopProcessing="true">
<match url="^$"/>
<conditions>
<add input="{HTTP_USER_AGENT}" pattern="^AlwaysOn$"/>
</conditions>
<action type="None"/>
</rule>
<rule name="Skip it all, if on localhost" stopProcessing="true">
<match url="^localhost$"/>
<conditions>
<add input="{HTTP_HOST}" pattern="^localhost$"/>
</conditions>
<action type="None"/>
</rule>
<rule name="Remove www" stopProcessing="true">
<match url="(.*)"></match>
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.(.*)$" />
<add input="{HTTP_HOST}" matchType="Pattern" pattern="^localhost$" negate="true" />
</conditions>
<action type="Redirect" url="https://{C:1}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
<rule name="Force HTTPS" enabled="true">
<match url="(.*)" ignoreCase="false" />
<conditions>
<add input="{HTTP_HOST}" matchType="Pattern" pattern="^localhost$" negate="true" />
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
【问题讨论】:
标签: c# .net azure url-rewriting web-config