You are overthinking this ( very dangerous and harmful for programmer/developer )..
Just use this logic in your page template:
<?php
//Check if user is logged in
if( is_user_logged_in() ) {
//The the stuff you want to show to logged-in users
}
else {
//Do something else, e.g show notice "You have to be logged in to view this content"
}
?>
Redirecting is a very bad idea because people will get confused easier than you might think!
If I click on a link and it redirects me back without any notice, I will try again.. And just in case one more time.. Then I will leave your site and probably share my bad experience with others because this feels like mocking.
IF you are talking about posts (do not confuse them with pages), I would recommend to:
- Add meta box to your post edit screen with checkbox
- Save the checkbox value as post meta if post is saved
Checkbox serves as a flag: if it’s checked, show post only to logged-in users.
Then the code in your post template (single-{post-type}.php) would look something like this:
<?php
//Get the post meta from database
$user_flag = get_post_meta( $post_id, 'user_flag', 'true' );
//Check if checkbox was checked and user is logged in
// OR
//If it was not checked, show content to everybody
if( ! $user_flag || $user_flag && is_user_logged_in() ) {
//The the stuff you want to show to logged-in users
}
else {
//Do something else, e.g show notice "You have to be logged in to view this content"
}
?>