WordPress.org

Forums

Redirect on my post is also redirecting my front page (1 post)

  1. mattman77777
    Member
    Posted 1 year ago #

    I am trying to set up a redirect on a post - http://matttalkstech.com/2013/04/30/sci-fi-movie-s…round-1-take-2/ ‎- so that users can only visit it once a day to prevent them from voting multiple times.

    The code I am using is

    <script>
    <!--
    // page to go to if cookie exists
    go_to = "http://matttalkstech.com/sci-fi-redirect/";
    
    // number of days cookie lives for
    num_days = 1;
    function ged(noDays){
    var today = new Date();
    var expr = new Date(today.getTime() + noDays*24*60*60*1000);
    return expr.toGMTString();
    }
    
    function readCookie(cookieName){
    var start = document.cookie.indexOf(cookieName);
    if (start == -1){
    document.cookie = "seenit=yes; expires=" + ged(num_days);
    } else {
    window.location = go_to;
    }
    }
    
    readCookie("seenit");
    // -->
    </script>

    [Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

    I inserted it into my post using the Per Post Scripts and Style plugin. The redirect works great on the post, but it is also redirecting my front page. None of my other pages appear to be affected by the redirect. Any suggestions?

Topic Closed

This topic has been closed to new replies.

About this Topic