IIS:URL Rewrite實現vue的地址重寫


vue-router

全局配置

 

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

 

 

 

 

URL Rewrite

1、添加規則

 

 

2、設置規則

使用正則表達式匹配網址,模式:就是正則表達式;

 

 條件可以設置服務器變量對應匹配,如上面只匹配www.local.com

 服務器變量

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

 

 

 這里的{R:0}就是上面正則表達式匹配的內容:可以通過測試模式查看;也可以通過正則表達式的分組匹配去做跳轉規則

 

 

 

3、web.config

打開可以看到剛才的配置自動寫入web.config的內容

    <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:

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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM