Redirect loop that is solved by exit()
-
I have the following code which runs for every request:
$current_url = home_url(add_query_arg(array()));
if ($current_url != home_url() . ‘/login’) {
wp_redirect(home_url() . ‘/login’);
exit;
}exit(“Already on login page.”);
When I leave in the exit(“Already on login page.”) code, I get redirected to the login page then the exit message “Already on login page” appears, as expected. If I delete the exit(“Already on login page.”) code, I get stuck in a redirect loop. I don’t know why it would loop since I am on the login page already and the wp_redirect function would not be called again. What is happening after the exit(“Already on login page.”) function which causes this redirect to be called again? It makes no sense to me.
PS – I have an additional check in the boolean statement which checks if the user is logged in but I have removed it here for simplification.
The topic ‘Redirect loop that is solved by exit()’ is closed to new replies.