0

I want non logged in users to be redirected to the homepage which has a login/register form. After logging in all pages will be accessable.

I've added the following code to my header.php

<?php if( !is_user_logged_in() )
wp_redirect('http://krins.frisweb.nl' ); exit(); ?>

This worked locally (with a localhost url) but after uploading the site to a test subdomain it's causing an error: ERR_TOO_MANY_REDIRECTS

If I change the url to something else the redirect is working again but for some reason it breaks when replacing the url with the url of the homepage/site.

Thanks for your help.

0

Next should be in a comment, not in a answer, but is too long, so I'm sorry posting here and hope it helps.

You don't post the code, but it seems you are experiencing and endless redirect.

Usually this happen when:

  1. The page is opened, user is not logged and so redirect
  2. The page is opened again, user is not logged and so redirect again

Luckily TOO_MANY_REDIRECTS error come or point 2. will repeat endless.

You have 2 solutions:

  1. When redirect from a page, make sure to redirect to a page that not trigger the redirect again
  2. If the previous is impossible add to redirect url a variable like '?noredirect=1' and before redirect check for this $_GET var

If I'm wrong, please post the code and debug informations and maybe someone can better help you.

  • Thanks, yes the homepage contains the redirect too which causes another redirect / infinity loop... Didn't thought about that yet. – NielsPilon Aug 21 '13 at 12:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.