【问题标题】:Url rewritting multiple domains and subfolders asp.mvcUrl 重写多个域和子文件夹 asp.mvc
【发布时间】:2011-11-22 00:55:02
【问题描述】:

我在 http://mydomain.com/mysite 上有一些网站,动态子网站很少 http://mydomain.com/mysite/category1, http://mydomain.com/mysite/othercategory2

我想从其他地址 http://otherdomain.com 访问 mysite/{dynamiccategoryname}。它应该适用于 mysite 和 mysite/category1 ...

http://otherdomain.com should show http://mydomain.com/mysite 
http://otherdomain.com/category1 should show http://mydomain.com/mysite/category1 

但不适用于重定向客户端

【问题讨论】:

  • 这只能使用 IIS 重定向设置来完成。
  • 但站点托管在一个应用程序池和站点中(多个主机名:mydomain.com 和 otherdomain.com)

标签: asp.net-mvc iis-7 url-rewriting


【解决方案1】:

这可以通过 URL 重写来完成。您基本上需要将主机名 otherdomain.com 的所有请求重写为 /mysite/*。这可以通过以下重写规则来完成:

<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Rewrite all request for otherdomain.com to /mysite">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="^otherdomain\.com$" />
                    </conditions>
                    <action type="Rewrite" url="/mysite/{R:0}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

另一种解决方案是在 IIS 中设置一个辅助站点,主机名 otherdomain.com 在同一 IP 上,但让该站点的路径指向 /mysite 文件夹的物理路径。但是,如果您在 otherdomain.com 上也需要 mydomain.com 的 ASP.NET MVC 应用程序,那当然是行不通的。但如果 otherdomain.com 是例如,它可能是一个解决方案。仅用于提供静态内容(图像、css、脚本)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-16
    • 2017-08-24
    • 2018-12-12
    • 1970-01-01
    • 2014-02-08
    • 2010-11-07
    相关资源
    最近更新 更多