简体   繁体   中英

Angular App Url always saying 404 on refresh after deploy on IIS

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 #.

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>

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

Step 1: Install IIS URL Rewrite Module

Step 2: Add a rewrite rule to 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM