问题
I have created a Virtual Directory on IIS (inetmgr) on my local PC and later converted it into IIS Web Application. The web application's root is: http://localhost/xyz/ When deployed and ran the application, I get the following error in the browser:
All html components 404 not found errors.
Added rewrite rules in web.config. I changed index.html's base href to ./xyz or ./ but no luck.
If I deploy it to root directory, everything resolves - not sure what's going wrong.
回答1:
1. Enable xyz
folder as a web application folder (See below picture)

2. Update base href, for example <base href="/spa/">
3. Set rewrite rule
<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" />
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
Hope it helps!
来源:https://stackoverflow.com/questions/43017193/angular-2-application-not-working-when-moved-into-iis-virtual-directory