IIS:URL Rewrite实现vue的地址重写

vue-router

全局配置html

 

const router = new VueRouter({
  mode: 'history',
  routes: [...]
})

 

 

 

 

URL Rewrite

一、添加规则

 

 

二、设置规则

使用正则表达式匹配网址,模式:就是正则表达式;vue

 

 条件能够设置服务器变量对应匹配,如上面只匹配www.local.comweb

 服务器变量正则表达式

https://docs.microsoft.com/en-us/previous-versions/iis/6.0-sdk/ms524602(v=vs.90)vue-router

 

 

 这里的{R:0}就是上面正则表达式匹配的内容:能够经过测试模式查看;也能够经过正则表达式的分组匹配去作跳转规则服务器

 

 

 

三、web.config

打开能够看到刚才的配置自动写入web.config的内容ide

    <system.webServer>
        <rewrite>
            <rules>
                <rule name="测试规则" stopProcessing="true">
                    <match url=".*" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="^www.local.com$" />
                    </conditions>
                    <action type="Redirect" url="http://www.asd.com/{R:0}" redirectType="Found" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>

 

<system.webServer>
    <rewrite>
      <rules>
        <rule name="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>
404/500跳转首页

 

 

 

 

资源: 工具

安装url-rewrite:post

https://www.iis.net/downloads/microsoft/url-rewrite测试

正则表达式工具:

http://deerchao.net/tools/regester/index.htm

 博客

https://shiyousan.com/post/635654920639643421

vue地址重写

https://router.vuejs.org/zh/guide/essentials/history-mode.html#%E5%90%8E%E7%AB%AF%E9%85%8D%E7%BD%AE%E4%BE%8B%E5%AD%90

相关文章
相关标签/搜索