[英]Force HTTPS via URL rewrite in web.config
I'm trying to force HTTPS via a web.config URL rewrite rule for a URL which includes a path. 我正在尝试通过web.config URL重写规则对包含路径的URL强制执行HTTPS。
eg http://my.domain.com/folder must be forced to use https://my.domain.com/folder 例如,必须强制http://my.domain.com/folder使用https://my.domain.com/folder
I'd also like to force HTTPS for all pages on their relative paths 我还要对相对路径上的所有页面强制使用HTTPS
eg http:// my.domain.com/folder/page.aspx forced to https:// my.domain.com/folder/page.aspx 例如,将http:// my.domain.com/folder/page.aspx强制设为https:// my.domain.com/folder/page.aspx
This is what I have: 这就是我所拥有的:
<rewrite>
<rules>
<rule name="Redirect to https">
<match url="(.*)"/>
<conditions>
<add input="{HTTPS}" pattern="Off"/>
<add input=”{REQUEST_METHOD}” pattern=”^get$|^head$” />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}"/>
</rule>
</rules>
</rewrite>
Check your casing and the type of quotes you are using. 检查外壳和所用报价的类型。 Also, the 2nd input method is invalid - the pattern isn't valid a regex.
另外,第二个输入法无效-模式对正则表达式无效。 This rule works for what you want:
该规则适用于您想要的:
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
Try this URL rewrite rule: 尝试以下URL重写规则:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="HTTP/S to HTTPS Redirect" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{SERVER_PORT_SECURE}" pattern="^0$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.