【问题标题】:IIS / MVC web.config rewriteIIS/MVC web.config 重写
【发布时间】:2017-07-07 01:22:12
【问题描述】:

我的服务器上有两个项目在同一个 ip 上运行。

  1. a.company.com (MVC)
  2. b.company.com (WEBAPI)

我想重定向; a.company.com/api/(.*) => **b.company.com/(.*)

这样,但我想隐藏 b.company.com 主机名。这意味着我想重写它,而不是重定向。

谢谢。

【问题讨论】:

    标签: asp.net-mvc iis asp.net-web-api url-rewriting


    【解决方案1】:

    您需要加载 URL 重写模块 2.0,该模块可通过平台安装程序获得。这将允许您进行服务器端 URL 重写。

    我不能确切地说你的规则应该是什么,但如果你在站点级别执行,你会在 system.webServer 部分的 web.config 中得到类似的东西:

        <rewrite>
            <rules>
                <rule name="rewrite" patternSyntax="Wildcard">
                    <match url="/api/*" />
                    <action type="Rewrite" url="/{R:1}" />
                </rule>
            </rules>
        </rewrite>
    

    您需要使用正确的捕获组来匹配您的情况。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-23
      • 2011-05-23
      • 1970-01-01
      • 2013-08-19
      • 2016-11-03
      • 2017-02-15
      • 1970-01-01
      • 2013-04-23
      相关资源
      最近更新 更多