前端页面部署之后刷新页面之后出现HTTP 错误 404.0 - Not Found错误问题解决

发布时间 2023-11-18 12:13:30作者: 望穿秋水

前端页面部署能正常访问,但是一旦刷新页面就报如下错误:404.0 - Not Found

 解决办法:下载IIS URL重写模版,并安装。下面为安装地址:

URL Rewrite : The Official Microsoft IIS Site

安装之后IIS中出现如下IIS重写模块:

点击进去添加规则,添加空白规则:

 

 配置好之后会自动生成web.config文件,如下图:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="xsw" patternSyntax="Wildcard">
                    <match url="*" />
                    <conditions logicalGrouping="MatchAny">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="/index.html" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

所以,安装好之后,也可以直接复制之前站点生成好的web.config文件,放到新站点根目录下即可。