2011-08-02 34 views
13

每当有人通过HTTP协议发出请求时,我会重写url以使其成为HTTPS。这是在web.config中的代码:重写规则错误:HTTP错误500.50 - URL重写模块错误。表达式“https://abc.com/{R:1”无法扩展

<rule name="Imported Rule 1-1" enabled="true" stopProcessing="true"> 
    <match url="^(?!https://).*" ignoreCase="false" /> 
    <conditions logicalGrouping="MatchAll"> 
     <add input="{SERVER_PORT}" pattern="80" ignoreCase="false" /> 
    </conditions> 
    <action type="Rewrite" url="https://abc.com/{R:1}" /> 
</rule> 

然而,当我浏览在http://我收到IIS错误

HTTP Error 500.50 - URL Rewrite Module Error. The expression "https://abc.com/{R:1}" cannot be expanded.

我怎样才能解决这个问题?我完全困惑。

+0

现在我就在此也。你有没有找到解决方案?如果是这样,请在此发布。 –

回答

14

这些匹配是从零开始的。

<action type="Rewrite" url="https://abc.com/{R:1}" /> 

因为只有一个匹配项,所以不起作用。您需要:

<action type="Rewrite" url="https://abc.com/{R:0}" /> 

此外,这不起作用,因为您只能匹配网站根下面的路径。

<match url="^(?!https://).*" ignoreCase="false" /> 

看起来你正在检查ssl。试试这个:

 <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> 
     <add input="{HTTPS}" pattern="^OFF$" /> 
     </conditions> 
-1

您可以通过web配置重定向到 希望这将有助于充分

<rule name="Redirect to WWW" stopProcessing="true"> 
    <match url=".*" /> 
    <conditions> 
     <add input="{HTTP_HOST}" pattern="^abc.com$" /> 
    </conditions> 
    <action type="Redirect" url="http://www.abc.com/{R:0}" redirectType="Permanent" /> 
</rule>