【问题标题】:URL Rewrite not working on IIS 10.0URL 重写在 IIS 10.0 上不起作用
【发布时间】:2017-11-10 22:47:17
【问题描述】:

我在 IIS 10.0 上使用 URL 重写,并在服务器级别 (applicationHost.config) 配置了以下规则。我已经在我的 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>

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

【问题讨论】:

  • 嗨,在这里思考一下。你在 IIS 中安装了 IIS HTTP Redirect 模块吗?

标签: asp.net iis url-rewriting


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    匹配正则表达式有问题。它不应该以斜线开头。正确的是^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 可能在不同的标头中

    【讨论】:

      猜你喜欢
      • 2012-12-23
      • 1970-01-01
      • 2023-03-08
      • 2013-07-26
      • 2015-01-29
      • 1970-01-01
      • 2012-10-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多