Redirect wordpress to subdirectory but keep access to wp-admin of main domain

How to redirect wordpress to subdirectory (or to another URL) but keep access to wp-admin of main domain

https://wordpress.stackexchange.com/questions/267767/how-to-301-redirect-to-subdirectory-but-keep-access-to-wp-admin-of-main-domain

If you, as an admin, need to access the front-end as well as the backend you can use a code snippet to grant that access.

The final code should be like this:

/**
* Redirect website to a subfolder or to another URL.
*/

if ( current_user_can('administrator') ) {
// Let him view the website
} else {
// Redirect him!
add_action( 'template_redirect', 'wp_maintance_mode' );

function wp_maintance_mode() {
wp_redirect( "http://new_url" ); 
// or if the folder is outside wordpress and lies under same url
//wp_redirect( home_url('/folder_name') );
exit;
} 
}