為什么會404NotFound
Internet Information Services (IIS)
第一步:安裝 IIS UrlRewrite
第二步:配置重寫URL規則
在你的網站根目錄中創建一個 web.config
文件,內容如下:
<?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>
配置完成后,在IIS上的URL 重寫頁面可以看見配置好的
或者,直接在IIS上配置,效果是和上面方法一樣:
最后點擊右側的應用即可添加成功
遺留問題
所有這些配置后,服務器就不再返回 404 錯誤頁面,因為對於所有路徑都會返回 index.html 文件。為了避免這種情況,你應該在 Vue 應用里面覆蓋所有的路由情況,然后在給出一個 404 頁面。