nginx配置自動跳轉


閱讀更多

希望實現的效果是,用戶只要訪問域名,自動跳轉到index.html頁面

原本配置為:

Plain代碼   收藏代碼
  1. location / {  
  2.     root   /users/apple/git_local/YAE/YAE/frontend;  
  3.     index  /portal/nail/index.html;  
  4. }  

這樣雖然可以達到目的,但是瀏覽器里的URL還是www.xxx.com。如果頁面上有鏈接使用相對路徑,就會發生404錯誤,所以需要配置為:

Plain代碼   收藏代碼
  1. rewrite ^/(index.html)?$ portal/nail/index.html redirect;  
  2.   
  3. location / {  
  4.     root   /users/apple/git_local/YAE/YAE/frontend;  
  5.     index  /portal/nail/index.html;  
  6. }  



瀏覽器的URL會變成www.xxx.com/portal/nail/index.html,這樣相對路徑就能正常訪問了

<div id="share_weibo">分享到:
  <a data-type="sina" href="javascript:;" title="分享到新浪微博"><img src="/images/sina.jpg"></a>
  <a data-type="qq" href="javascript:;" title="分享到騰訊微博"><img src="/images/tec.jpg"></a>
</div>
  • 2014-05-15 19:55
  • 瀏覽 848
  • 評論(0)
  •   <li class="last"><a href="https://www.iteye.com/wiki/blog/2070350" target="_blank" class="more">查看更多</a></li>
    </ul>    
    
評論


免責聲明!

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



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