哈希 url 转换为长 url htaccess? php?

发布于 2024-12-10 08:55:19 字数 303 浏览 0 评论 0原文

我已经用哈希构建了整个网页(http://example.com/videos#video01),但问题是当我想在 Facebook 上分享时,显然它无法识别哈希,所以我的问题是:有没有办法将哈希 URL 转换或重定向到长社交友好 URL?

解决方案: 我又尝试了一次 bit.ly 的 API,我得到了 50 个视频,每个视频的网址末尾都有一个哈希值。我制作了一个小缓存脚本(bit.ly 有限制),并用 PHP 编写了一个“foreach”,看起来 bit.ly 接受哈希值。

不管怎样,谢谢。

I have constructed my entire webpage with hashes (http://example.com/videos#video01), but the problem is when I want to share on facebook obviously it doesn't recognize the hash, so my question is: Is there a way to transform or redirect the hash url to a long social-friendly-url?

Solution:
I tried one more time with bit.ly's API, I got 50 videos to show each with a hash at the end of the url. I made a little cache script (bit.ly has a limit) and I wrote with PHP a "foreach", seem like bit.ly accepts hashes.

Thanks anyway.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

动听の歌 2024-12-17 08:55:19

# 和后面的所有内容不会发送到服务器。在您的情况下,您仅发送 http://example.com/videos

The # and everything after is not sent to a server. In your case you're only sending http://example.com/videos.

少女七分熟 2024-12-17 08:55:19

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

在控制器顶部调用此函数或http://example.com/videos/index.php code>:

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

New Link format: http://example.com/videos?name=video01

Call this function toward top of controller or 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");
    }
}

Sanitization snippet from this highly ranked answer: https://stackoverflow.com/a/2021729/1296209

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文