在 IIS 上部署后,Angular App Url 在刷新时总是说 404 [英] Angular App Url always saying 404 on refresh after deploy on IIS

查看:28
本文介绍了在 IIS 上部署后,Angular App Url 在刷新时总是说 404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 windows server 的 IIS 上部署了一个使用 angular 6 开发的应用程序.现在我面临一个问题,即在导航应用程序时,如果我正在刷新页面,它会显示 404 - 未找到文件或目录.我查看了与此问题相关的帖子并尝试应用修复.但没有运气.我不想在我的网址中使用 #.我只想像 http://example.xyz.com/detail/12 一样使用网址

I deployed an application developed using angular 6 on IIS of windows server. Now I am facing one issue that on navigating the app if I am refreshing the page then it says 404 - File or directory not found. I looked at the posts related to this issue and tried to apply fix. but no luck. I do not want to use # with my urls. I just want to use urls simply like http://example.xyz.com/detail/12

如果我使用#,那很好,但我不想使用#.

If I am using # then its fine but I don't want to use #.

我也尝试添加 web.config,但没有成功.任何人都可以在这里帮助如何解决此问题,以便在刷新时可以打开我想重新加载的同一页面.

I tried to add a web.config as well, but no luck. Can any one help here how to fix this issue so that on refresh same page can be opened that I want to reload.

 <?xml version="1.0" encoding="utf-8"?>
<configuration>

<system.webServer>
  <rewrite>
    <rules>
      <rule name="Angular Routes" 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="./index.html" />
      </rule>
    </rules>
  </rewrite>
</system.webServer>

</configuration>

推荐答案

点击此链接解决此问题在 IIS 上托管的 Angular 2:HTTP 错误 404或者只是

Follow this link to fix this issue Angular 2 Hosted on IIS: HTTP Error 404 or just

步骤 1:安装 IIS URL 重写 模块

Step 1: Install IIS URL Rewrite Module

第 2 步:向 web.config 添加重写规则

<?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <system.webServer>
        <rewrite>
          <rules>
            <rule name="AngularJS Routes" 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>

这篇关于在 IIS 上部署后,Angular App Url 在刷新时总是说 404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆