我已经用散列(http://example.com/videos#video01)构建了我的整个网页,但问题是,当我想在facebook上分享时,它显然不认识哈希,所以我的问题是:有没有办法将散列url转换或重定向到一个长期的社交友好型url?
解决方案:我再试一次使用bit.ly的API,我在url的末尾显示了50个视频,每个视频都带有一个散列。我做了一个小缓存脚本(bit.ly有一个限制),我用PHP写了一个"foreach",看起来bit.ly接受散列。
不管怎样,谢谢你。
发布于 2011-10-18 18:55:05
#和之后的所有内容都没有发送到服务器。在您的情况下,您只发送http://example.com/videos。
发布于 2016-03-09 19:40:51
新链接格式: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
https://stackoverflow.com/questions/7812162
复制相似问题