2011-11-19 75 views
4

我真的被困在这一个......强制一些页面通过HTTPS和其他HTTP到HTTP ...有可能吗?

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

UPDATE:发现这篇文章:Rewrite http to https on some pages only using .htaccess。自2010年3月以来没有答案...!

+0

”自2010年3月以来没有回答...!“ ==>你为什么使用IIS?我本可以在不到眨眼的时候用阿帕奇回答。更好,更快,更安全和免费(以*每种方式)。对不起,我忍不住。 –

+0

谢谢奥利弗。是的,它比我想象的要容易得多。 :P 据我所知,这个URLRewrite插件可以和htaccess一样。但是,是的,我更喜欢htaccess(围绕更长的时间和更多的资源等)。我相信你甚至可以在IIS中使用htaccess。 – jon

回答

7

所以我落得这样做是:

  1. 力HTTPS为需要它的网页。
  2. 将所有其他页面强制为HTTP EXCEPT,用于点#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> 
相关问题