2012-02-29 65 views
2

想知道是否有人可以提供帮助。非常感谢!HTTP到HTTPS重定向只有一个URL

问题

  • blog.example.com
  • cool.example.com

    重定向到https://www.example.com

目标

我们正在努力只能重定向

  • http://example.com

  • http://www.example.com

    https://www.example.com

当前代码

在web.config中目前的代码是这样的。卡住<match url="(.*)">

以下是重写规则的其余部分。

<system.webServer>  
<rewrite> 
    <rules> 
     <rule name="Redirect to https"> 
      <match url="(.*)" /> 
      <conditions> 
      <add input="{SERVER_PORT}" pattern="443" negate="true" /> 
      </conditions> 
      <action type="Redirect" url="https://www.example.com" /> 
     </rule> 
    </rules> 
</rewrite> 
<modules runAllManagedModulesForAllRequests="true"/> 
<defaultDocument enabled="true"> 
    <files> 
    <clear/>  
    <!--Remove this line or place below to deprecate--> 
    <add value="default.aspx"/> 
    <add value="index.html"/> 
    <add value="index.php"/> 
    <add value="default.html"/> 
    </files> 
</defaultDocument> 

回答

2

修改<match url="(.*)" />只包括example.comwww.example.com - 现在你匹配的所有URL。

http://learn.iis.net/page.aspx/461/creating-rewrite-rules-for-the-url-rewrite-module/

+0

我不是太熟悉的正则表达式。你的意思是这个''? – Danger14 2012-03-01 00:00:10

+0

你可以使用正则表达式或通配符 - 我总是使用UI来设置规则,这种方式更容易;-) – 2012-03-01 00:02:22

+0

对不起,你会介意给我一个URL,我可以学习如何编写这个规则?什么是UI? – Danger14 2012-03-01 00:08:10

0

试试这个:

<rule name="Rewrite HTTP to HTTPS" stopProcessing="false" enabled="false"> 
<match url=".*" /> 
<conditions> 
    <add input="{HTTPS}" pattern="off" /> 
    <add input="{HTTP_HOST}" type=”Pattern” pattern="^(www\.)?example.com$"> 
</conditions> 
<action type="Redirect" url="https://www.example.com{REQUEST_URI}" appendQueryString="false" redirectType="Permanent" /> 

+0

-1结束的工作 - 这不会重定向到'blog.example.com' ? – 2012-03-01 00:03:09

+0

关键是要显示一条工作规则(对于捕获非https流量具有不同的条件),可以根据评论中的指示进行微调。 – 2012-03-01 00:06:07

+0

这是微调OP是有问题.. – NotMe 2012-03-01 00:14:45