如何配置 IIS 重写

How to config IIS Rewrite

我的项目使用 php 和 angular,它托管在 IIS 中。我在 angular 中打开 html5Mode,这意味着我可以使用像 localhost/home 这样的路由,而不是 locahost/#/home

我的问题是当我将 url(例如:http://localhost/home)复制并传递到另一个选项卡或浏览器时,IIS return 错误

Requested URL http://localhost/home/

Physical Path <physical link>\link\

我想使用 angular 路由(而不是 ui-router)来处理我应用程序中的所有路由。如何配置 URL Rewrite 使其理解所有只需要指向 home 的路由?

我的项目路线是index.html。这是一个普通的 html 文件。

在 Asp.net MVC 中,我这样配置路由:

routes.MapRoute(
                name: "Renewal SPA",
                url: "{*catchall}",
                defaults: new { controller = "Home", action = "Index" });

如何对 php 做同样的事情?

您应该像这样在配置文件(或 IIS 中)中配置 IIS 重写:

<system.webServer>
 <rewrite>
 <rules> 
  <rule name="Main Rule" stopProcessing="true">
    <match url=".*" />
    <conditions logicalGrouping="MatchAll">
      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />                                 
      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    </conditions>
    <action type="Rewrite" url="/" />
  </rule>
  </rules>
 </rewrite>
</system.webServer>

Be sure that URL Rewrite installed on your IIS (download it from here).

查看这篇文章: Configure your server to work with html5Mode