【问题标题】:AngularJS HTML5 Mode URL Rewrite to www. VersionAngularJS HTML5 模式 URL 重写为 www。版本
【发布时间】:2015-09-16 14:55:07
【问题描述】:

我在 Azure 中托管我的 AngularJS 站点,但是当我只想对 www.url 执行 URL 重写时遇到了问题。版本。我正在使用 HTML5 模式进行路由。

如果我有以下 web.config 并刷新页面,我会收到一条错误消息,指出“您要查找的资源已被删除、名称已更改或暂时不可用。”

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<rewrite>
  <rules>
    <clear/>
    <rule name="WWW Rewrite" enabled="true">
      <match url="(.*)"/>
      <conditions>
        <add input="{HTTP_HOST}" negate="true" pattern="^www\."/>
      </conditions>
      <action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent"/>
    </rule>
  </rules>
</rewrite>
  </system.webServer>
</configuration>

如果我将 web.config 保留如下,刷新没有问题,但我无法重定向到 www。我的网站版本:

<configuration>
    <system.web>
  <compilation debug="true" targetFramework="4.5" />
  <httpRuntime targetFramework="4.5" />
</system.web>
  <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>
</configuration>

我怎样才能让这两个场景一起工作?

【问题讨论】:

    标签: angularjs azure iis


    【解决方案1】:

    尝试添加

    <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
    

    到你的条件块。

    【讨论】:

      猜你喜欢
      • 2019-11-10
      • 2015-11-06
      • 2016-08-14
      • 2015-10-04
      • 1970-01-01
      • 2014-02-22
      • 2014-08-04
      • 2012-09-18
      • 2016-11-06
      相关资源
      最近更新 更多