Url rewriting MVC4URL重写给了我一个404.4,尽管重写看起来还可以

Url rewriting MVC4URL重写给了我一个404.4,尽管重写看起来还可以,url-rewriting,asp.net-mvc-4,iis-express,Url Rewriting,Asp.net Mvc 4,Iis Express,我正在尝试重写url以更改请求,例如 到 我将URL重写规则弹出到web配置中,如下所示 <rewrite> <rules> <rule name="SiteReWrite" stopProcessing="true"> <match url="(.*)" /> <action type="Rewrite" url="http://bar.com/{C:1}/"/>

我正在尝试重写url以更改请求,例如

我将URL重写规则弹出到web配置中,如下所示

<rewrite>
  <rules>
      <rule name="SiteReWrite" stopProcessing="true">
          <match url="(.*)" />
          <action type="Rewrite" url="http://bar.com/{C:1}/"/>
          <conditions>
              <add input="{HTTP_HOST}" pattern="(.*)\.bar\.com" />
          </conditions>
      </rule>
  </rules>
</rewrite>

这是它应该做的。
我不希望用户看到新的url,他们应该认为自己在foo.bar.com上,而不是bar.com/foo上。这只是我在mvc应用程序中的一些路由


有人知道它为什么做这种奇怪的行为吗?我正在为此使用IIS express 8,我还没有尝试使用IIS。

您应该
重定向
,而不是
重写

<rewrite>
  <rules>
      <rule name="SiteReWrite" stopProcessing="true">
          <match url="(.*)" />
          <action type="Redirect" url="http://bar.com/{C:1}/"/>
          <conditions>
              <add input="{HTTP_HOST}" pattern="(.*)\.bar\.com" />
          </conditions>
      </rule>
  </rules>
</rewrite>


如果确实要重写,则必须通过安装ARR(应用程序请求路由)模块将IIS设置为反向代理。

由于我不希望用户看到url更改,因此无法使用重定向。然而,我应该提到的是,所有的子域都将指向同一个站点。一旦我仔细考虑了一下,并且对重写模块进行了更多的阅读,我修改了一个MSDN示例,如下所示;这就像一个符咒

<rewrite>
  <rules>
    <rule name="Rewrite subdomain">
      <match url="(.*)" /> <!-- rule back-reference is captured here -->
      <conditions>
        <add input="{HTTP_HOST}" pattern="^([^.]+)\.bar\.com$" /> <!-- condition back-reference is captured here -->
      </conditions>
      <action type="Rewrite" url="{C:1}/{R:1}" /> <!-- rewrite action uses back-references to condition and to rule when rewriting the url -->
    </rule> 
  </rules>
</rewrite>

<rewrite>
  <rules>
    <rule name="Rewrite subdomain">
      <match url="(.*)" /> <!-- rule back-reference is captured here -->
      <conditions>
        <add input="{HTTP_HOST}" pattern="^([^.]+)\.bar\.com$" /> <!-- condition back-reference is captured here -->
      </conditions>
      <action type="Rewrite" url="{C:1}/{R:1}" /> <!-- rewrite action uses back-references to condition and to rule when rewriting the url -->
    </rule> 
  </rules>
</rewrite>