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

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

问题描述

我在Windows服务器的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>

推荐答案

点击此链接可解决此问题 Angular 2托管在IIS: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天全站免登陆