2012-04-23 76 views
0

下面是我的web.config文件。我想要将http url自动重定向到https。我尝试了下面的方法,但它不起作用。 需要在SSL设置中选中需要SSL的IIS7。 任何人都可以帮忙。 感谢重定向http到https asp/iis

<configuration> 
<configSections> 
    <sectionGroup name="system.webServer"> 
     <sectionGroup name="rewrite"> 
      <section name="rewriteMaps" overrideModeDefault="Allow" /> 
      <section name="rules" overrideModeDefault="Allow" /> 
     </sectionGroup> 
    </sectionGroup> 
</configSections> 
<system.webServer> 
    <rewrite> 
     <rules> 
      <rule name="Redirect to HTTPS" enabled="true" stopProcessing="true"> 
       <match url="^(.*)$" /> 
       <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> 
        <add input="{HTTPS}" pattern="off" /> 
       </conditions> 
       <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Found" /> 
      </rule> 
     </rules> 
    </rewrite> 
    <defaultDocument> 
     <files> 
      <add value="index.asp" /> 
     </files> 
    </defaultDocument>  
</system.webServer> 
<system.web> 
    <customErrors mode="Off" />  
    <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" /> 
</system.web> 

回答

1

取消选中“要求SSL” - 对重定向工作,你必须先接受HTTP初始请求。

编辑

第二点。您正在选择基于HTTPS的输入。你需要否定这样的条件:

<conditions logicalGrouping="MatchAll" trackAllCaptures="false"> 
    <add input="{HTTPS}" pattern="off" negate="true" /> 
</conditions> 
+0

完成。现在该网站在http中打开并且没有重定向到https – 2012-04-23 06:59:37

+0

IIS7中是否存在不允许重写规则工作的设置? – 2012-04-23 07:04:40

+0

@NishantSaini请看我更新的答案。 – McGarnagle 2012-04-23 07:14:13