how do I redirect to 'domain.com/sub' for unlogged users, when the url is without the "one_time_login" parameter? This should not work when a user is trying to login via sub.domain.com/wp-admin. Have no idea. I understand that htaccess cant make this? Thanks for your help!
1 Answer
This should work for what you're looking to achieve;
add_action( 'template_redirect', 'redirect_to_specific_page' );
function redirect_to_specific_page() {
if ( ! is_user_logged_in() && ! is_page('one_time_login') ) {
wp_redirect( 'domain.com/sub', 301 );
exit;
}
}
This should be added to your theme (or child theme) functions.php file
-
really thanks for your help, finally its this code for me: <code> add_action( 'template_redirect', 'redirect_to_specific_page' ); function redirect_to_specific_page() { if (! is_user_logged_in() && !strpos($_SERVER['REQUEST_URI'], "one_time_login_token") && !strpos($_SERVER['REQUEST_URI'], "wp-admin") && !strpos($_SERVER['REQUEST_URI'], "new-login")) { wp_redirect( '/new-login', 301 ); exit; } } </code> ```– GraigDec 4, 2021 at 14:38