2012-03-31 74 views
0

我正在使用的項目是使用pushState,但由於Internet Explorer無法正確處理,所以在更改URL時使用了shebang。有沒有設置.htaccess來允許網址中的shebang,但刪除它並重定向它。截至目前,如果我要轉到http://www.mydomain.com/#!/whatever.php它只顯示我的索引頁。但我想它做的是,如果你轉到http://www.mydomain.com/#!/whatever.php,重定向到http://www.mydomain.com/whatever.php如何設置.htaccess以允許在網址中使用shebang

+0

花費一點時間用Wireshark;客戶端_never_發送'#'或任何後面的內容到服務器。 – sarnold 2012-03-31 23:52:39

回答

0

好的,所以我想出了問題的答案。所以javascript是唯一可以確定的方法,因爲在URL中使用shebang它將引導您訪問域的索引頁,但仍然保持URL相同。所以我剛剛在我的頁面頂部添加了以下內容。

$(document).ready(function(){ 
    var loc = self.document.location; 
    if(loc.hash){ 
     var href = loc.hash.split("#!/"); 
     window.location = loc.protocol +'//'+ loc.host +'/'+href[1]; 
    } 
}); 
0

不,使用.htaccess是不可能的,因爲#後一切都沒有被髮送到服務器的。你將不得不使用JavaScript來做重定向。

+0

我試過使用javascript,但是當你在路徑中使用'shebang'標籤時,javascript不會檢測到任何東西。如果嘗試'alert(window.location.pathname);'並且它只是在嘗試'http://www.mydomain.com/#!/ index.php'時顯示'/'作爲路徑 – Bobby 2012-04-01 18:32:07

+0

使用:'alert( window.location.hash);'獲得'#'(哈希)部分 – stewe 2012-04-01 19:25:15