1. Creating Rewrite Rules for the URL Rewrite Module
   - Link: 
https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module
2. Build Angular2 Project
    ng build --prod --aot(option)
3. Config IIS to dist folder
- Copy dist folder to another folder (ex: deploy)
- Add new Website and pointer to this folder (ex: deploy/dist)
- Add web.config file to the root folder to re-write url (ex: deploy/dist)
<?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="/" />
   </rule>
 </rules>
  </rewrite>
  </system.webServer>
</configuration>
Result on IIS
 
Không có nhận xét nào:
Đăng nhận xét