0

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 1

0

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

1
  • 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> ```
    – Graig
    Dec 4, 2021 at 14:38

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.