user2136875
user2136875

Reputation: 21

Page not found displays when I refresh a page

I have developed Angular 7 Application. I want to host in Normal Windows 7 Desktop (It does not have IIS installed). When I refresh a page/route, it is saying

"404 Not Found - The requested URL was not found on the server". enter image description here

I don't want to use "HashLocationStrategy".

I tried creating web.config as follows and added in the project folder

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <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" />
          </conditions>
          <action type="Rewrite" url="http://localhost/sp/" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

In the above code, I tried keeping Rewrite URL as "/" but did not help Still I am getting same error.

My index.html page

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
  <title>Title</title>

  <base href="./" />

  <meta name="viewport" content="viewport-fit=cover, width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
  <meta name="format-detection" content="telephone=no" />
  <meta name="msapplication-tap-highlight" content="no" />

  <link rel="icon" type="image/png" href="assets/icon/favicon.png" />

  <!-- add to homescreen for ios -->
  <meta name="apple-mobile-web-app-capable" content="yes" />
  <meta name="apple-mobile-web-app-status-bar-style" content="black" />
<link rel="stylesheet" href="styles.30b5b974b5c7cd59b7d1.css"></head>

<body>
  <app-root></app-root>
<script type="text/javascript" src="runtime.2ec62019cc97e19fb61f.js"></script><script type="text/javascript" src="polyfills.b7025f5354b70ae0544f.js"></script><script type="text/javascript" src="scripts.ccb1b8327b72db7af87a.js"></script><script type="text/javascript" src="main.1d9ddad52d76d8c93cdd.js"></script></body>

</html>

I except the page reloads even after refreshing but I am getting 404 Error

Can you help me in resolving the issue / how to configure web.config. Thanks in advance

Upvotes: 2

Views: 93

Answers (1)

Adrita Sharma
Adrita Sharma

Reputation: 22203

In index.html:

<base href="/">

and in web.config:

 <action type="Rewrite" url="/" />

should work.

Upvotes: 2

Related Questions