IIS部署createWebHistory路由模式的Vue项目

大王快跑丶 / 2023-07-13 / 原文

接口使用NetCore,前端使用Vue3.+
网站部署目录如下

  • api(虚拟应用程序)
  • web
  • index.html
    需要在服务器上按照URLRewrite
    下载地址:https://www.iis.net/downloads/microsoft/url-rewrite
    安装后在网站根目录下创建“web.config”文件,内容如下
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Vue路由Html5模式下F5刷新报404" stopProcessing="true">
		<!-- 只要不包含"/api/"的url就重写到 "/" -->
          <match url="^(?!api\/).*" />
          <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>