After hosting Angular2 app on IIS direct url is not working

前端 未结 3 1871
日久生厌
日久生厌 2020-12-24 04:07

We have developed Angular2 App.

It is working fine while we are running under angular-cli with \'ng serve\'.

Once we host the app to IIS 7.5, we can browse t

相关标签:
3条回答
  • 2020-12-24 04:10

    [windows hosting] Create text file and call it "web.config" open it and past the content below then make sure it is in the root directory in your hosting

    <?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>
    

    BEST OF LUCK :) It is rewarding when I save someone else time!

    0 讨论(0)
  • 2020-12-24 04:30

    An even simpler change worked for me, using Angular 4.0 and IIS 6.1. This allowed me to use a named site instead of the default folder or the rewriting above. I just changed the base href from '/' to the name of my app folder:

    <head>
        <base href="MyApp">
    ...
    

    Hope this works for others!

    0 讨论(0)
  • 2020-12-24 04:31

    I get this resolved by doing following steps ..

    1. Downloaded URL Rewriter module from https://www.microsoft.com/en-au/download/details.aspx?id=7435

    2. Added following to my web.config

    <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="/" />
            </rule>
          </rules>
        </rewrite>
      </system.webServer>
    </configuration>

    1. Setting up base tag in index.html. It should be immediately after <head> tag

    <base href="/"/>

    These three steps will set you up for deployment of Angular2 / Angular App with html5mode url on IIS 7.5 or IIS 8.0

    Hope this will help. I have to go through few answers to get this one resolved.

    0 讨论(0)
提交回复
热议问题