Ssl IIS重写规则将非www重定向到动态域等效且始终为https
我想要的是,所有非https或没有Ssl IIS重写规则将非www重定向到动态域等效且始终为https,ssl,redirect,iis,url-rewriting,web-config,Ssl,Redirect,Iis,Url Rewriting,Web Config,我想要的是,所有非https或没有www前缀的请求都被重定向到:”https://www.“+域名+可能的查询字符串参数 我有一个重写规则(): 我想这正是我想要的,但是如何使本例中的域名动态化并在重定向中保留它(就像第一个代码示例那样)?(原始海报在过去6个月内未登录,因此我在这里提问) 此外,我还检查了,这似乎也是一个很好的候选人: <rule name="Redirect top domains with non-www to www" stopProcessing="true"&g
www
前缀的请求都被重定向到:”https://www.“+域名+可能的查询字符串参数
我有一个重写规则():
我想这正是我想要的,但是如何使本例中的域名动态化并在重定向中保留它(就像第一个代码示例那样)?(原始海报在过去6个月内未登录,因此我在这里提问)
此外,我还检查了,这似乎也是一个很好的候选人:
<rule name="Redirect top domains with non-www to www" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern=".*localhost.*" negate="true" />
<add input="{HTTP_HOST}" pattern=".*stage\..*" negate="true" />
<add input="{HTTP_HOST}" pattern=".*dev\..*" negate="true" />
<add input="{HTTP_HOST}" pattern="^([^\.]+)\.([^\.]+)$" />
</conditions>
<action type="Redirect" url="https://www.{HTTP_HOST}/{R:1}" redirectType="Permanent" />
<serverVariables>
<set name="Redirect" value="false" />
</serverVariables>
</rule>
<rule name="Force HTTPS" enabled="true" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern=".*localhost.*" negate="true" />
<add input="{HTTP_HOST}" pattern=".*stage\..*" negate="true" />
<add input="{HTTP_HOST}" pattern=".*dev\..*" negate="true" />
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
重定向到,我仍然会收到安全异常。
首先,我强烈建议您获得一个新的SSL证书,该证书支持example.com
和www.example.com
。对于大多数SSL提供者来说,这种证书实际上是相当标准的,它不必是通配符证书。否则,您将无法像现在这样处理对的请求,我认为这是一个问题
你最重要的两条规则应该如下
p.S.301重定向被浏览器缓存一段时间。在测试新规则之前,先为浏览器清除301重定向缓存
<rule name="Force WWW and SSL" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^[^www]" />
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://www.zzz.com/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
<rule name="Redirect top domains with non-www to www" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern=".*localhost.*" negate="true" />
<add input="{HTTP_HOST}" pattern=".*stage\..*" negate="true" />
<add input="{HTTP_HOST}" pattern=".*dev\..*" negate="true" />
<add input="{HTTP_HOST}" pattern="^([^\.]+)\.([^\.]+)$" />
</conditions>
<action type="Redirect" url="https://www.{HTTP_HOST}/{R:1}" redirectType="Permanent" />
<serverVariables>
<set name="Redirect" value="false" />
</serverVariables>
</rule>
<rule name="Force HTTPS" enabled="true" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern=".*localhost.*" negate="true" />
<add input="{HTTP_HOST}" pattern=".*stage\..*" negate="true" />
<add input="{HTTP_HOST}" pattern=".*dev\..*" negate="true" />
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>