将 HTTP 重定向到 HTTPS,但包含 web.config 的页面除外
Redirect HTTP to HTTPS except one page with web.config
我希望将所有页面从 HTTP 重定向到 HTTPS,但根目录中的一页 (pagename.php) 除外,该页面需要作为 HTTP 工作(需要重定向回 HTTP)。我目前有以下代码可以从 none-www 重定向到 www 并将 HTTP 重定向到 HTTPS。
<rewrite>
<rules>
<rule name="Redirect to WWW" stopProcessing="true" >
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\." negate="true"/>
</conditions>
<action type="Redirect" url="https://www.{HTTP_HOST}{HTTP_URL}" redirectType="Permanent" appendQueryString="false" />
</rule>
<rule name="Redirect to HTTPS">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="OFF"/>
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{HTTP_URL}" redirectType="Permanent" appendQueryString="false" />
</rule>
</rules>
<outboundRules>
<rule name="Add Strict-Transport-Security when HTTPS" enabled="true">
<match serverVariable="RESPONSE_Strict_Transport_Security"
pattern=".*" />
<conditions>
<add input="{HTTPS}" pattern="on" ignoreCase="true" />
</conditions>
<action type="Rewrite" value="max-age=31536000" />
</rule>
</outboundRules>
</rewrite>
我需要此角色中的其他角色或异常来重写特定 URL 或将特定 URL 重定向到 HTTP(我只需要 2 个 URL 作为 HTTP 工作,它们只是带有 .php 页面的 URL扩展名和所有其他的都不同)。
非常感谢你的帮助。
您需要一个带有 negate="true" 的条件来为您的 php 文件添加例外。
<rule name="Redirect to HTTPS">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="OFF"/>
<add input="{URL}" pattern="(.*).php" negate="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{HTTP_URL}" redirectType="Permanent" appendQueryString="false" />
</rule>
<!--EDIT-->
<rule name="Redirect to HTTP">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="ON"/>
<add input="{URL}" pattern="(.*).php" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}{HTTP_URL}" redirectType="Permanent" appendQueryString="false" />
</rule>
我希望将所有页面从 HTTP 重定向到 HTTPS,但根目录中的一页 (pagename.php) 除外,该页面需要作为 HTTP 工作(需要重定向回 HTTP)。我目前有以下代码可以从 none-www 重定向到 www 并将 HTTP 重定向到 HTTPS。
<rewrite>
<rules>
<rule name="Redirect to WWW" stopProcessing="true" >
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\." negate="true"/>
</conditions>
<action type="Redirect" url="https://www.{HTTP_HOST}{HTTP_URL}" redirectType="Permanent" appendQueryString="false" />
</rule>
<rule name="Redirect to HTTPS">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="OFF"/>
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{HTTP_URL}" redirectType="Permanent" appendQueryString="false" />
</rule>
</rules>
<outboundRules>
<rule name="Add Strict-Transport-Security when HTTPS" enabled="true">
<match serverVariable="RESPONSE_Strict_Transport_Security"
pattern=".*" />
<conditions>
<add input="{HTTPS}" pattern="on" ignoreCase="true" />
</conditions>
<action type="Rewrite" value="max-age=31536000" />
</rule>
</outboundRules>
</rewrite>
我需要此角色中的其他角色或异常来重写特定 URL 或将特定 URL 重定向到 HTTP(我只需要 2 个 URL 作为 HTTP 工作,它们只是带有 .php 页面的 URL扩展名和所有其他的都不同)。
非常感谢你的帮助。
您需要一个带有 negate="true" 的条件来为您的 php 文件添加例外。
<rule name="Redirect to HTTPS">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="OFF"/>
<add input="{URL}" pattern="(.*).php" negate="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{HTTP_URL}" redirectType="Permanent" appendQueryString="false" />
</rule>
<!--EDIT-->
<rule name="Redirect to HTTP">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="ON"/>
<add input="{URL}" pattern="(.*).php" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}{HTTP_URL}" redirectType="Permanent" appendQueryString="false" />
</rule>