哈希url转换为长url访问?php?
我用哈希(哈希url转换为长url访问?php?,php,.htaccess,url-rewriting,Php,.htaccess,Url Rewriting,我用哈希(http://example.com/videos#video01),但问题是当我想在facebook上分享时,它显然无法识别散列,所以我的问题是:有没有办法将散列url转换或重定向到一个长的社交友好url 解决方案: 我又尝试了一次bit.ly的API,我得到了50个视频,每个视频在url的末尾都有一个散列。我制作了一个小缓存脚本(bit.ly有一个限制),我用PHP编写了一个“foreach”,看起来bit.ly接受哈希 无论如何,谢谢。之后的#和所有内容都不会发送到服务器。在您的
http://example.com/videos#video01
),但问题是当我想在facebook上分享时,它显然无法识别散列,所以我的问题是:有没有办法将散列url转换或重定向到一个长的社交友好url
解决方案:
我又尝试了一次bit.ly的API,我得到了50个视频,每个视频在url的末尾都有一个散列。我制作了一个小缓存脚本(bit.ly有一个限制),我用PHP编写了一个“foreach”,看起来bit.ly接受哈希
无论如何,谢谢。之后的#和所有内容都不会发送到服务器。在您的情况下,您只发送
http://example.com/videos
新链接格式: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");
}
}
这个排名很高的答案中的消毒片段:顺便说一句,我尝试了bit.ly的API,但没有成功。我知道,有办法解决这个问题吗?