2014-03-13 88 views
1

我在Web.config文件中的条目<system.webServer>下:重定向不是重定向

<rewrite> 
    <rules> 
    <rule name="Redirect to HTTPS" stopProcessing="true"> 
     <match url="(.mydomain.com*)" /> 
     <conditions> 
     <add input="{HTTPS}" pattern="^OFF$" /> 
     </conditions> 
     <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" /> 
    </rule> 
    </rules> 
</rewrite> 

我期望这http://www.mydomain.com请求将被重定向到https://www.mydomain.com。但是,这没有发生。

规则的格式有问题吗?还必须做其他事情以启用重定向吗?

这是在IIS 8下的Windows 2012计算机上运行.RewriteModule列在该网站的模块下。

回答

1

删除"(.mydomain.com*)"并将其设置为"(.*)"

<rule name="HTTP to HTTPS redirect" stopProcessing="true"> 
    <match url="(.*)" /> 
    <conditions> 
     <add input="{HTTPS}" pattern="off" ignoreCase="true" /> 
    </conditions> 
    <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" /> 
</rule> 
+0

更改后的行为相同。 –

+0

@EricJ。试试这个。对不起,我以前的答案。 – rpax

+0

这样做!任何想法,为什么?之前的模式也是匹配的。 –

1

确保IIS重写模块(可安装使用Web Platform Installer安装之后,你可以使用IIS管理器see, configure, and test the rewrite rules

编辑:我注意到你说你验证模块安装酷最有可能的!这是一个规则本身的问题,使用IIS提供的测试工具来验证它是否以你期望的方式工作

编辑2:我认为你的规则的问题是你的匹配URL语法根据http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference#Rule_pattern_syntax,默认语法是ECMAScript正则表达式,这意味着如果你想匹配.字符,你必须使用\.

+0

对不起,迟到已安装RewriteModule编辑。我现在查看管理重写规则的链接。 –

+0

当我输入测试模式www.mydomain.com时,它告诉我输入的URL与模式匹配。尽管如此,它并没有重定向。 –