Welcome to StackExchange. As mentioned on comments by @aravona and @Rup it will be harder to give you a good answer without more context.
In any case, I think you have a couple basic approaches to achieve what you want: using WordPress template_redirect
hook or .htaccess files rules (or NGINX configuration rules in case you are using NGINX instead of Apache).
The most performant would be .htaccess
file rules, and NGINX configuration file rules, but it would be more prone to redirect errors or breaking things on the admin side if you are not experienced with these. Therefore, I suggest avoid it and stick to the template_redirect
hook.
Using the Template Redirect Hook
You can use the following code in a theme, a plugin or Must-Use Plugin (i.e. MU Plugin). I suggest using either a plugin or, even better, a MU Plugin, which is called before normal plugins.
/**
* Redirect All WordPress frontend requests to the /wp-admin/
*
* Redirect All WordPress frontend requests to /wp-admin/, except for WP Rest API endpoints.
* Adapted from a idea by BraadMaring at https://github.com/BraadMartin/only-rest-api .
*
* @uses wp_safe_redirect
* @uses admin_url
*/
function wpse355549_redirect() {
if ( ! is_admin() ) {
wp_safe_redirect( admin_url(), 301 );
exit;
}
}
add_action( 'template_redirect', 'wpse355549_redirect', 10 );
Basically, this will check if the request isto a /wp-admin/ URL. It f not, it will safely redirect to the /wp-admin/
Caveat: some customizer related pages are not detected by is_admin
. API endpoints will also be accessible.