javascript - Angular App - 重写问题

标签 javascript angularjs apache .htaccess mod-rewrite

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

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

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

index.html

最佳答案

app.js 中设置 $locationProvider.html5Mode(true) 后,在 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

关于javascript - Angular App - 重写问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38350338/

相关文章:

javascript - Angularjs ng-重复 : iterate over a special object fields

apache - 使用 apache2 服务器配置匹配/拒绝访问所有子目录

javascript - $http 是否对 params 对象进行排序?

javascript - 我希望我的菜单图标与汉堡菜单重叠

javascript - 单击元素后切换 W3Schools 响应式顶部导航

javascript - 谷歌图表 mysql PHP

angularjs - 从 angularjs + flow.js 中的 Controller 动态传递 flow-init 目标的上传 URL

java - 如何更改代理后面的 Hudson 上的 BaseUrl?

java - 如何在 Apache Tomcat 上部署的 java 中的系统启动时自动启动一个功能

javascript - 将水平 ScrollView 的高度设置为索引内容高度