简体   繁体   English

URL重写不适用于IIS 10.0

[英]URL Rewrite not working on IIS 10.0

I'm using URL Rewrite on IIS 10.0 and have the following rule configured at the server level (applicationHost.config). 我在IIS 10.0上使用URL重写,并在服务器级别(applicationHost.config)配置了以下规则。 I've tried it in my web.config to no avail as well. 我也没有在我的web.config中尝试过它。

   <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>

Is there anything immediately obviously wrong here? 这里有什么明显的错误吗? I want any external traffic trying to hit /admin to get redirected to an error page, and only allow a single internal IP block to access it. 我希望尝试点击/ admin的所有外部流量都重定向到错误页面,并且仅允许单个内部IP块对其进行访问。 Pulling my hair out over here. 把我的头发拉过来。

您可能需要安装“应用程序请求路由”,它是IIS的扩展,可在以下位置获得: https : //www.iis.net/downloads/microsoft/application-request-routing

There is a problem in match regexp. 匹配正则表达式中存在问题。 It shouldn't start with slash. 它不应该以斜杠开头。 Correct is ^admin ( ^ means start of url) 正确的是^admin^表示网址的开头)

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

And i have couple of notes: 我有几点注意事项:

1) For IP validation better to have regexp like that: 10.30.[0-9]{1,3}.[0-9]{1,3} instead of 10.30.*.* 1)对于IP验证,最好使用如下正则表达式: 10.30.[0-9]{1,3}.[0-9]{1,3}而不是10.30.*.*

2) Depends on your load balancer and network infrastructure, but you might need to check {HTTP_X_Forwarded_For} header instead {REMOVE_ADDR} , because client's IP might be in different header 2)取决于您的负载平衡器和网络基础结构,但是您可能需要检查{HTTP_X_Forwarded_For}标头而不是{REMOVE_ADDR} ,因为客户端的IP可能在不同的标头中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM