How to identify if referrer is a 301 redirect

前端 未结 5 1549
悲&欢浪女
悲&欢浪女 2020-12-21 15:46

I\'m implementing a slug system for my website at the moment. I plan to redirect invalid slugs to the correct on that is stored in the database. E.g.

5条回答
  •  轮回少年
    2020-12-21 15:59

    I think the only useful option is to use a cookie.

    When a URL with the wrong slug is requested, set a cookie for that URL without the slug:

    $path = substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '/')+1);
    setcookie('wrong-slug', 1, 0, $path);
    

    Then test if such a cookie exists and display your message:

    if (isset($_COOKIE['wrong-slug'])) {
        echo 'The location of this resource has changed. Please update your bookmarks.';
    }
    

提交回复
热议问题