Vue 在 IIS 中重整 404 問題

問題 : Vue 使用 History Mode 部屬到 IIS 重新整理時會返回404

下載 Url Rewrite

  • 依造步驟一路往下安裝即可

在 dist 中設置 web.config

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Handle History Mode and custom 404/500" 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>
  • 若不想 build 後去寫 web.config,可以把 web.config 加入到 public 中,這樣就會自動加入