0

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.

kinduff
  • 122
  • 2
  • 9

2 Answers2

0

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

Community
  • 1
  • 1
webaholik
  • 1,619
  • 1
  • 19
  • 30
0

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

Mob
  • 10,958
  • 6
  • 41
  • 58