我必须从 Angular 应用程序中删除 #
- 我在 apache 服务器上托管的 Angular 应用程序中有 2 个 View (index.html 和 page1.html)
- 创建了指向放置文件的文件夹的别名(apps-demo)
网址将为:https://servername/apps-demo
当我导航到 page1 时,它将是:https://servername/apps-demo/Page1
但是当我重新加载页面时,我得到 404 not found
我尝试在 .htaccess 、 ssl.conf (虚拟主机内部)中编写重写规则
最佳答案
在 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/