【问题标题】:Force some pages over HTTPS and others to HTTP... is it possible?强制某些页面通过 HTTPS 和其他页面通过 HTTP ......这可能吗?
【发布时间】:2012-01-01 16:54:46
【问题描述】:

我真的被这个困住了......

基本上,我正在尝试使用 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>

更新:找到这篇文章:Rewrite http to https on some pages only using .htaccess。自 2010 年 3 月以来没有任何答复...!

【问题讨论】:

  • “自 2010 年 3 月以来没有任何答复......!” ==> 你为什么使用 IIS?我可以在不到一眨眼的时间里用 Apache 回答。更好、更快、更安全和免费(以每一种方式)。抱歉,我帮不上忙。
  • 谢谢奥利弗。是的,结果比我想象的要容易。 :P 据我所知,这个 URLRewrite 插件可以做和 htaccess 一样的事情。但是,是的,我也更喜欢 htaccess(使用时间更长、资源更多等)。我相信您甚至可以将 htaccess 与 IIS 一起使用。

标签: iis redirect ssl rewrite url-rewriting


【解决方案1】:

所以我最终做的是:

  1. 对需要它的页面强制使用 HTTPS。
  2. 强制所有其他页面使用 HTTP,但第 1 点中的页面以及这些页面上引用的“/styles”和“/images”文件夹除外。

由于页面使用相对路径,它们会自动分别通过 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>

【讨论】:

    猜你喜欢
    • 2011-07-06
    • 2014-01-22
    • 1970-01-01
    • 1970-01-01
    • 2016-07-28
    • 1970-01-01
    • 2011-01-07
    • 1970-01-01
    • 2019-01-03
    相关资源
    最近更新 更多