2017-09-05 117 views

回答

2

哈希標記是瀏覽器唯一的概念,從來沒有發送到服務器。所以你不能在nginx中重寫。因爲當你訪問http://www.example.com/my-path-here#hashvalue nginx服務器將只發送http://www.example.com/my-path-here

你需要的是Javascript來處理這樣的事情給你。下面是一個示例html頁面,它可以做到這一點

<html> 
<head> 
    <script> 
     var loc = window.location; 
     if (!loc.pathname.endsWith("/")) 
      loc.replace(loc.origin + loc.pathname + "/" + loc.hash); 
    </script> 
    </head> 
<body> 
    <h1> You are here - 
    <script> 
     document.write(loc.href); 
    </script> 
    </h1> 
</body> 
</html>