通过HTTPS和其他人强制某些页面到HTTP ...是否可能?

jon*_*jon 4 iis ssl redirect rewrite url-rewriting

我真的被困在这一个......

基本上,我正在使用IIS的URLRewrite插件尝试使用SSL创建2个页面.但我还需要强制所有其他页面到HTTP(叹气 - 不要问).

但是如果我通过HTTP强制其他页面,那么当您查看SSL页面时,您将收到安全警告.我试图通过检查HTTP_REFERER是否是SSL页面来解决这个问题,然后让它通过SSL发送给该页面.这不起作用,因为如果有人单击SSL页面上的链接,那么它将保留在SSL上.

这甚至可能吗?......

到目前为止,这是我所得到的:

<rewrite>
    <rules>
        <rule name="Force HTTPS Login" stopProcessing="true">
            <match url="(.+)login.aspx" />
            <conditions>
                <add input="{HTTPS}" pattern="^OFF$" />
            </conditions>
            <action type="Redirect" url="https://{HTTP_HOST}/{R:0}" redirectType="Permanent" />
        </rule>
        <rule name="Force HTTPS Payments" stopProcessing="true">
            <match url="(.+)payments.aspx" />
            <conditions>
                <add input="{HTTPS}" pattern="^OFF$" />
            </conditions>
            <action type="Redirect" url="https://{HTTP_HOST}/{R:0}" redirectType="Permanent" />
        </rule>
        <rule name="Others Force HTTP" stopProcessing="true">
            <match negate="true" url="((.+)login.aspx|(.+)payments.aspx)" />
            <conditions>
                <add input="{HTTPS}" pattern="^ON$" />
                <add input="{HTTP_REFERER}" negate="true" pattern="(.+)login.aspx" />
                <add input="{HTTP_REFERER}" negate="true" pattern="(.+)payments.aspx" />
            </conditions>
            <action type="Redirect" url="http://{HTTP_HOST}/{R:0}" redirectType="Permanent" />
        </rule>
    </rules>
</rewrite>
Run Code Online (Sandbox Code Playgroud)

更新:发现这篇文章:仅使用.htaccess在某些页面上将http重写为https.自2010年3月以来没有答案......!

jon*_*jon 7

所以我最终做的是:

  1. 强制HTTPS为需要它的页面.
  2. 对于#1点中的页面以及这些页面上引用的"/ styles"和"/ images"文件夹,强制所有其他页面为HTTP EXCEPT.

由于页面使用相对路径,因此它们分别通过HTTP/HTTPS自动使用样式/图像.

<rewrite>
    <rules>
        <rule name="Force HTTPS Login" stopProcessing="true">
            <match url="(.*)/login.aspx" />
            <conditions>
                <add input="{HTTPS}" pattern="^OFF$" />
            </conditions>
            <action type="Redirect" url="https://{HTTP_HOST}/{R:0}" redirectType="Permanent" />
        </rule>
        <rule name="Others Force HTTP" stopProcessing="true">
            <match url="(((.*)/login.aspx)|((.*)/styles(.*))|((.*)/images(.*)))" negate="true" />
            <conditions>  
                <add input="{HTTPS}" pattern="^ON$" />
            </conditions>
            <action type="Redirect" url="http://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
        </rule>
    </rules>
</rewrite>
Run Code Online (Sandbox Code Playgroud)