当发布Vue项目到IIS中时,默认情况下是无法直接通过浏览器输入二级URL进行访问的,例如打开“http://www.test.com"能正常打开,但直接输入"http://www.test.com/user"就会显示无法找到页面。这是因为IIS无法找到这个URL地址,因此需要配置IIS进行URL转发。
以下是步骤:
1、在IIS中安装一个叫“URL重写”功能
打开IIS,通过Web平台安装程序,安装一个名为URL重写的组件。如果无法安装或找不到该组件,可以通过以下URL进行直接下载安装: URL Rewrite : The Official Microsoft IIS Site
安装完成后,在网站根目录创建一个名为web.config的文件,并复制以下内容进去:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="vuejs" 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>
复制进去后保存退出,即可完成,此时就可以通过URL进行直接访问不同路径的页面了。