2009-10-08 123 views
33

我试图从形式重写URL:从https重写URL://到http://在IIS7

https://example.com/about 

的形式

http://example.com/about 

使用IIS7 URL rewriting

<!-- http:// to https:// rule --> 
<rule name="ForceHttpsBilling" stopProcessing="true"> 
    <match url="(.*)billing/(.*)" ignoreCase="true" /> 
    <conditions> 
    <add input="{HTTPS}" pattern="off" ignoreCase="false" /> 
    </conditions> 
    <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}{REQUEST_URI}" /> 
</rule> 

<!-- https:// to http:// rule -->  
<rule name="ForceNonHttps" stopProcessing="true"> 
    <match url="(.*)billing/(.*)" ignoreCase="true" negate="true" /> 
    <conditions> 
     <add input="{SERVER_PORT}" pattern="^443$" /> 
    </conditions> 
    <action type="Redirect" redirectType="Found" url="http://{HTTP_HOST}{REQUEST_URI}" /> 
</rule> 

我不知所措;我一直在浏览网页的例子,并尝试我能想到的每一种语法。对于任何https请求,我所指定的重写规则根本不会工作,全部为,好像所有的https://请求对于重写引擎都是不可见的。

规则正常工作;见下面的答案。

+0

对我来说,气味就像一个基本的安全'功能' – 2009-10-08 08:05:02

+0

这对我来说就像一个服务器故障问题... – 2009-10-08 08:47:02

+0

@Charlie,no。这是编码和管理问题之一,所以请将其留在它开始的网站上(如很多脚本问题) – 2009-10-08 10:18:54

回答

25

原来,我有端口:443绑定到不同的网站!

上述重写规则对http://正确地工作到https://重写,反之亦然 - 虽然可能有更优化或简单的方法来完成它。

在这里让这个问题留给未来的航行者来发现,因为我没有在网上看到https:// http://重写场景的很多好例子。

+1

Ouch。在这里爆炸头。 O – 2009-10-08 13:25:06

+1

我发现使用上述https规则导致我的https页面上的所有CSS,JavaScript和图像资源都被作为http获取。我放弃了这个规则,并添加了一个出站规则,将我的安全页面上的href标记重写为http:// {HTTP_HOST}/{R:0},强制从https转换为http。不会无意中手动导航到使用https的非安全页面,但这对我来说很好 – 2011-01-25 01:13:54

+0

Pat James,我也遇到过这个问题。你介意分享你的出站规则吗? – StronglyTyped 2012-02-06 19:18:53

1

您的解决方案工作,但问题是:您的第二条指令杀死任何链接的第一条指令不是(。)billing /(。),包括您的css,js和图像。

您可以使用此HTTPS到http规则:

<rule name="HTTPS to HTTP redirect" stopProcessing="true"> 
<match url="(.*)" /> 
<conditions> 
<add input="{RequiresSSL:{R:1}}" pattern="(.+)" negate="true" /> 
<add input="{HTTPS}" pattern="on" ignoreCase="true" /> 
<add input="{REQUEST_URI}" pattern="^(.+)\.(?!aspx)" negate="true" /> 
</conditions> 
<action type="Redirect" redirectType="Found" url="http://{HTTP_HOST}/{R:1}" /> 
</rule> 
5

这个职位是有点老了,但我想回答。我正在使用ASP.Net MVC3,而Fabio上面的回答对我并不适用。我想出了一个最简单的方法来处理HTTPS重定向到HTTP,同时仍允许有效的HTTPS页面请求安全内容只是加入我上面的HTTPS/HTTP白名单规则重定向:

<rule name="WhiteList - content folder" stopProcessing="true"> 
     <match url="^content/"/> 
     <conditions logicalGrouping="MatchAll" trackAllCaptures="false"/> 
     <action type="None"/> 
    </rule> 
    <rule name="Redirect to HTTPS" stopProcessing="true"> 
     <match url="(.*)billing/(.*)" ignoreCase="true" /> 
     <conditions> 
     <add input="{HTTPS}" pattern="^OFF$" /> 
     </conditions> 
     <action type="Redirect" url="https://{HTTP_HOST}/billing/" redirectType="SeeOther" /> 
    </rule> 
    <rule name="ForceNonHttps" stopProcessing="true"> 
     <match url="(.*)billing/(.*)" ignoreCase="true" negate="true" /> 
     <conditions> 
     <add input="{SERVER_PORT}" pattern="^443$" /> 
     </conditions> 
     <action type="Redirect" redirectType="Found" url="http://{HTTP_HOST}{REQUEST_URI}" /> 
    </rule> 
0

请首先考虑结合 HTTPS到您的网站下面进行重定向模块来工作是必不可少的

最终在web.config中的一部分(以便与自签名有效证书绑定您的Web应用程序)重定向HTTPSHTTP

<rewrite> 
    <rules> 
     <rule name="Force NonHTTPS" stopProcessing="true"> 
      <match url="(.*)" /> 
      <conditions> 
       <add input="{HTTPS}" pattern="on" /> 
      </conditions> 
      <action type="Redirect" url="http://{HTTP_HOST}/{REQUEST_URI}" /> 
     </rule> 
    </rules> 
</rewrite> 

如果需要在重写模块的等效IIS GUI见下文图像

enter image description here

源:看tech-net为一步引导更多的细节和步骤。

+0

也看到这篇文章https://serverfault.com/q/292374/105675 – 2017-05-13 06:53:55