【问题标题】:Rewrite from local path to external domain - C# MVC IIS 7.5 URL从本地路径重写到外部域 - C# MVC IIS 7.5 URL
【发布时间】:2019-02-14 02:13:05
【问题描述】:

我无法在 MVC 应用程序中进行 url 重写,因为我需要将所有请求从 https://www.thisdomain.com/assets/* 等同于 https://www.thatdomain.com/assets/* 例如

<link rel="stylesheet" href="/assets/css/app.css">

https://www.thatdomain.com/assets/css/app.css加载资源

我目前在 web.config 中有这个

<system.webServer>
<rewrite>
    <rules>
    <rule name="Map Assets" stopProcessing="true">
    <match url="assets/(.*)" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^www.otherdomain.com/assets/$" />
    </conditions>
    <action type="Rewrite" url="/{R:1}" appendQueryString="true" />
    </rule>
</rules>
</rewrite>
</system.webServer>

并将其添加到我的 RouteConfig.cs 中

routes.IgnoreRoute("assets/");

Url Rewrite 已安装在服务器上。

任何帮助将不胜感激。

【问题讨论】:

标签: c# iis model-view-controller url-rewriting iis-7.5


【解决方案1】:

一些问题: 那些“www.thisdomain.com”和“www.otherdomain.com”,托管在同一台服务器上? 您确定要“重写”而不是“重定向”吗?

我什至不确定是否可以重写到另一个域。 您可以重写资源路径或名称,但域对我来说没有多大意义。 但是重定向可以配置如下:

<rewrite>
    <rules>
    <rule name="Map Assets" stopProcessing="true">
    <match url="assets/(.*)" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="www.thisdomain.com" />
    </conditions>
    <action type="Redirect" url="www.otherdomain.com/assets/{R:1}" appendQueryString="true" />
    </rule>
</rules>
</rewrite>

【讨论】:

    猜你喜欢
    • 2015-05-11
    • 1970-01-01
    • 2012-05-23
    • 1970-01-01
    • 1970-01-01
    • 2014-06-21
    • 2013-01-06
    • 1970-01-01
    • 2018-09-06
    相关资源
    最近更新 更多