2

I am attempting to use url rewrite rules in my web.config to always load index.html to avoid refresh and deep link issues. I want to use the HTML5 routing approach. I get errors like the following loading my javascript files:

Uncaught SyntaxError: Unexpected token <        polyfills.bundle.js:1

The unexpected '<' above is because it's trying to load my index.html as the javascript file which is obviously an issue.

My base href in index.html is:

  <base href="/">

My url rewrite looks like:

<rule name="angular-rewrite" enabled="true" stopProcessing="true">
<match url="(.*)" />
 <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
    <add input="{HTTP_HOST}" pattern="^(www\.)?test\.mySite\.net$" />
 </conditions>
 <action type="Rewrite" url="/mySite/index.html" />

All the angular files are located in a subdirectory on the web server: /mySite/. This is necessary because multiple sites are hosted in sibling directories using other url rewrites.

I was thinking I may need an additional rule that points files to /mySite/ however, the above rule seems to affect files even though I have the IsFile negate option.

The only way I've been able to get this fully working is if I use the following base href in conjunction with the above rewrite rule:

  <base href="/mySite/">

The problem with this is that my url becomes: test.mysite.net/mySite/login. I want it to be: test.mysite.net/login

DeviantSpark
  • 80
  • 1
  • 9
  • This is the same issue i've had. The only way i was able to get it working was to use the fully qualified name in the base href tag. See my previous answer here: https://stackoverflow.com/questions/48332488/setting-up-angular-deep-linking-on-iis/49000034#49000034 – RMuesi Feb 27 '18 at 19:41

0 Answers0