• I’m not sure I understand how I can create a redirect that only redirects the main domain for users not logged in. Currently, the 301 redirect does so for any and all domain visits, whether logged in or not…

Viewing 3 replies - 1 through 3 (of 3 total)
  • yeah, im wondering the same thing. i can’t seem to make it work, help would be much appreciated!

    Thread Starter darkmatter661

    (@darkmatter661)

    I found a different solution. No plugin, just add this to your functions.php

    if (
      !in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php'))
      && !is_admin()
      && !is_user_logged_in()
    ) {
      wp_redirect('https://www.mysite.com/landingpage', 301);
      exit;
    }

    Just replace https://www.mysite.com/landingpage with the URL you want your non-logged in users to be redirected to.

    Since I’m also using WP Lockdown, I added ‘wpadmin’ (my custom URL for logging in) to the array.

    I think I know how to redirect only logged-in users, but it doesn’t work consistently for me — it works for a while and then it doesn’t redirect not-logged users. I’m using it along with WP-Members plugin, which works great except that people can see my blog page with all the posts titles and I don’t want that.

    Anyway, back to you, the way I think it works is that you can redirect a specific url or I guess you can also use a regular expression, by first creating it and then editing, like this:

    Go to redirects, add a a new redirection. Once it is created, click to edit it. You will have a field for logged in users and another for logged out –add a target url only if they should be redirected, if not, leave blank, for each as desired.

    Is this what you were looking for?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Redirect only for non logged users?’ is closed to new replies.