2011-10-18 22 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