AngularJS with HTML5mode (true) in IIS and <default document>

I have a simple application running on IIS 8.0 (arvixe hosting) that uses AngularJS for the SPA framework. I have included html5mode and linked the tag to index.html (root file), I also set this file as in web.config. I know you have to rewrite the server records that I have.

I want to achieve the following:

The user enters "domain.com" and loads the domain.com/home website. Of course the url is actually domain.com/index.html/home, but html5mode handles this with rewrites.

Here is app.config and that's ok.

  .config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider ) {
$routeProvider
    .when('/home', {
        templateUrl: 'templates/home.html',
        controller: 'HomeController'
    })
    .when('/login', {
        templateUrl: 'templates/login.html',
        controller: 'LoginController'
    })
    .when('/forum', {
        templateUrl: 'templates/forum.html',
        controller: 'ForumController'
    })
    .when('/rebellinks', {
        templateUrl: 'templates/rebellinks.html',
        controller: 'RebelLinksController'
    })
    .when('/events', {
        templateUrl: 'templates/events.html',
        controller: 'EventsController'
    })
    .when('/oldnews', {
        templateUrl: 'templates/oldnews.html',
        controller: 'OldNewsController'
    })
    .otherwise({
        redirectTo: '/home'
    });

//use HTML5 History API
$locationProvider.html5Mode(true);
   }]);

      

Web.Config file for IIS:

 <system.webServer>
    <rewrite>
      <rules>
        <clear />       
        <!--<rule name="jsRule" stopProcessing="true">
          <match url=".js" />
          <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" />
          </conditions>
          <action type="None" />
        </rule>-->

        <rule name="SRBShome" enabled="true" stopProcessing="true">
          <match url="^(.*)$" />
          <action type="Rewrite" url="/index.html" />
        </rule>
        <rule name="AngularJS" enabled="false" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
          </conditions>
          <action type="Rewrite" url="/index.html" />
        </rule>        
      </rules>
    </rewrite>
    <defaultDocument enabled="true">
      <files>
        <clear />
        <add value="index.html" />
        <add value="home.html" />
      </files>
    </defaultDocument>

      

What it is - load domain.com/home when the user visits the site but the .js files get carried over when I added a special rule in rewrite to prevent them from being overwritten, but I think my template is in the SRBShome rule to work properly.

Any help was appreciated.

+3


source share


1 answer


Allowed it with changing rewrite rules below. This allows index.html to be loaded into IIS. For some reason the web.config doesn't work for this setting. So now when user requests domain.com rewrite '/index.html' then AngularJS 'html5Mode starts and cleans up urls and removes hashbang.



 <rewrite>
      <rules>
        <clear />        
        <rule name="SRBShome" enabled="true" stopProcessing="true">
          <match url="^(.+)$" negate="true" />
          <conditions>
            <add input="{REQUEST_URL}" pattern="^(.+)$" negate="true" />
          </conditions>
          <action type="Rewrite" url="/index.html" logRewrittenUrl="true"/>
          <!--<match url="^.com" />
          <action type="Rewrite" url="/index.html" />-->
        </rule>
        <rule name="AngularJS" enabled="true" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
          </conditions>
          <action type="Rewrite" url="/index.html" />
        </rule>        
      </rules>
    </rewrite>

      

+13


source







All Articles