ASP.NET MVC and Subdomains Urls



我有一个虚拟的应用程序在~/博客使用这个子域名blog.fujiy.net

为了获得正确的链接,我使用以下配置:

<rewrite>
  <rules>
    <rule name="Remove Virtual Directory">
      <match url=".*" />
      <action type="Rewrite" url="{R:0}" />
    </rule>
  </rules>
</rewrite>

但是,如果任何人访问blog.fujiy.net/blog,它不会重定向到blog.fujiy.net。

我不能修复这个。我尝试了很多配置....每次我尝试做一个条件,如果url开始于/blog/IIS总是返回true,然后我得到一个无限循环

正则表达式让我害怕,但试试这个;它似乎在一个快速测试中起作用:

<rewrite>
    <rules>
        <rule name="Remove Virtual Directory" stopProcessing="true">
            <match url="(.*)" />
            <conditions>
                <add input="{HTTP_HOST}" pattern="^blog..*" />
                <add input="{PATH_INFO}" pattern="^/blog" />
            </conditions>
            <action type="Redirect" url="/" redirectType="Permanent" />
        </rule>
    </rules>
</rewrite>

唯一开箱即用的场景是:

您有两个或多个应用程序:称它们为server.example.com/foo和server.example.com/bar。你可以配置IIS的重写来做一个简单的子域->应用程序路径映射,例如:foo.example.com -> server.example.com/foo;Foo.example.com/path -> server.example.com/foo/path;Bar.example.com/path -> server.example.com/bar/path等。在这些示例中,子域本身必须直接映射到应用程序根目录。

为了解决这个问题,foo.example.com/customers/view/42将映射到server.example.com/foo/customers/view/42,如果您使用标准的{controller}/{action}/{id}路由,则将其标记为{controller = customers, action = view, id = 42}。

最新更新