2011-10-18 31 views
0

我已經構建了我的整個網頁與哈希(http://example.com/videos#video01),但問題是當我想在Facebook上分享顯然它不認可哈希,所以我的問題是:有沒有一種方法來轉換或重定向的哈希網址到一個長期的社會友好的網址?哈希url轉換爲一個很長的URL htaccess? PHP的?

解決方案: 我想一個更多的時間與bit.ly的API,我得到了50級的視頻在URL的末尾,以顯示每一個哈希值。我做了一個小緩存腳本(bit.ly有一個限制),我用PHP寫了一個「foreach」,看起來像bit.ly接受哈希。

無論如何。

+0

順便說一句,我試圖與位.ly的API並沒有工作。 – kinduff

回答

0

#之後的所有內容都不會發送到服務器。在你的情況下,你只發送http://example.com/videos

+0

我知道,有沒有辦法解決這個問題? – kinduff

0

新鏈接的格式:http://example.com/videos?name=video01

調用此函數向控制器或http://example.com/videos/index.php的頂部:

function redirect() 
{ 
    if (!empty($_GET['name'])) { 
     // sanitize & validate $_GET['name'] 
     // Remove anything which isn't a word, whitespace, number 
     // or any of the following caracters -_~,;[](). 
     // If you don't need to handle multi-byte characters 
     // you can use preg_replace rather than mb_ereg_replace 
     $file = mb_ereg_replace("([^\w\s\d\-_~,;\[\]\(\).])", '', $_GET['name']); 
     // Remove any runs of periods 
     $file = mb_ereg_replace("([\.]{2,})", '', $file); 
     $valid = file_exists('pathToFiles/' . $file); 
     if ($valid) { 
      $url = '/videos#' . $file; 
     } else { 
      $url = '/your404page.php'; 
     } 
     header("Location: $url"); 
    } 
} 

消毒從這個高度排名回答片段:https://stackoverflow.com/a/2021729/1296209