【问题标题】:Angular App - rewrite issueAngular App - 重写问题
【发布时间】:2016-07-13 11:24:10
【问题描述】:

我必须从 Angular 应用程序中删除 #

  1. 我在 apache 服务器上托管的 Angular 应用程序中有 2 个视图(index.html 和 page1.html)
  2. 创建的别名 (apps-demo) 指向放置文件的文件夹

网址将是:https://servername/apps-demo
当我导航到第 1 页时,它将是:https://servername/apps-demo/Page1
但是当我重新加载页面时,我得到 404 not found
我曾尝试在 .htaccess 、 ssl.conf (在虚拟主机内)中编写重写规则

index.html

【问题讨论】:

  • 在没有 html5mode 的情况下使用。
  • 我必须从应用程序中删除#。只有当我可以将 html5Mode 设置为 true 时,我才能做到这一点

标签: javascript angularjs apache .htaccess mod-rewrite


【解决方案1】:

$locationProvider.html5Mode(true) 设置为app.js 之后,在web.config 中编写规则。

希望,它会有所帮助。

  <system.webServer>
    <rewrite>
      <rules>
        <rule name="AngularJS" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
          </conditions>
          <action type="Rewrite" url="/" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>

在我的 index.html 中,我将其添加到

<base href="/">

不要忘记在服务器上安装 iis 的 url 重写器。

此外,如果您使用 Web Api 和 IIS,此匹配 url 将无法正常工作,因为它会更改您的 api 调用。因此,添加第三个输入(条件的第三行)并给出一个模式,该模式将排除来自 www.yourdomain.com/api 的调用

对于 apache,此链接可能会有所帮助 enter link description here

【讨论】:

  • 当我们在 iis 上托管它时,它在 windows 中有效。我知道这一点,我在 apache 服务器中也需要同样的功能
  • 你看到链接了吗,它解释了apache?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-12
  • 1970-01-01
  • 2018-02-07
  • 2018-09-06
  • 1970-01-01
  • 2013-07-22
相关资源
最近更新 更多