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

相關文章
相關標籤/搜索