add_action('template_redirect', 'apollo_redirect_root_only');
function apollo_redirect_root_only() {
// Only run on front-end (not in admin or REST/API requests)
if (is_admin() || wp_doing_ajax() || wp_is_json_request()) {
return;
}
$request_uri = $_SERVER['REQUEST_URI'] ?? '';
$script_name = $_SERVER['SCRIPT_NAME'] ?? '';
// Remove query string
$request_uri = parse_url($request_uri, PHP_URL_PATH) ?: '';
// Normalize: remove leading/trailing slashes for easier checking
$request_path = trim($request_uri, '/');
$script_path = trim($script_name, '/');
// Conditions that should be redirected:
// - Direct access to root: /, /index.php, /index.html
// - Or when WordPress is loading the home page without any path
$is_root_access = (
empty($request_path) ||
$request_path === 'index.php' ||
$request_path === 'index.html' ||
$script_path === 'index.php'
);
if ($is_root_access && !is_user_logged_in()) { // optional: allow logged-in users to bypass
// Meta refresh + JavaScript fallback + HTTP refresh header
wp_redirect('https://auth.apollo.rio.br/', 302);
exit;
// Alternative pure meta-refresh (if you really want tag):
/*
echo '
Redirecting...
Redirecting...';
exit;
*/
}
// Any other URL (including /any-folder/...) is allowed normally
}
Option 2: Pure PHP (non-WordPress) – place at the very top of your root index.php
PHP)
/*
echo '
Redirecting...
If you are not redirected automatically, click here.
';
exit;
*/
}