Url重写多个域和子文件夹asp.mvc

时间:2011-09-21 14:42:13

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

我在 http://mydomain.com/mysite 上有一些网站,其中包含少量动态子网站http://mydomain.com/mysite/category1http://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 

,但没有重定向客户端

1 个答案:

答案 0 :(得分:0)

这可以通过URL重写来完成。您基本上需要使用hostname 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中设置辅助站点,在同一IP上使用hostname otherdomain.com,但让该站点的路径指向/ mysite文件夹的物理路径。但是如果你需要在otherdomain.com上使用mydomain.com的ASP.NET MVC应用程序当然也不行。但是,如果otherdomain.com是例如,它可以是一个解决方案。仅用于提供静态内容(图像,CSS,脚本)。