2017-11-10 186 views
0

我在IIS 10.0上使用URL重写,并在服务器级别(applicationHost.config)配置了以下规则。我已经在我的web.config中尝试过,但也无济于事。URL重写无法在IIS 10.0上工作

<rewrite> 
     <globalRules> 
      <rule name="redirect"> 
       <match url="/admin" /> 
       <conditions> 
        <add input="{REMOTE_ADDR}" pattern="10.30.*.*" negate="true" /> 
       </conditions> 
       <action type="Rewrite" url="/error" /> 
      </rule> 
     </globalRules> 
    </rewrite> 

这里有什么明显的错误吗?我希望任何外部流量尝试点击/管理以重定向到错误页面,并且只允许单个内部IP块访问它。把我的头发拉出来。

+0

嗨,想出这里的盒子。您是否在IIS中安装了IIS HTTP重定向模块? –

回答

0

匹配正则表达式存在问题。它不应该以斜杠开始。正确的是^admin^指URL的开始)

<rule name="redirect"> 
    <match url="^admin" /> 
    <conditions> 
     <add input="{REMOTE_ADDR}" pattern="10.30.*.*" negate="true" /> 
    </conditions> 
    <action type="Rewrite" url="/error" /> 
</rule> 

,我有两点要注意:

1)IP验证最好是有正则表达式一样认为:10.30.[0-9]{1,3}.[0-9]{1,3}代替10.30.*.*

2)取决于您的负载平衡器和网络基础设施,但您可能需要检查{HTTP_X_Forwarded_For}标头,而不是{REMOVE_ADDR},因为客户端的IP可能位于不同标头中