Hook into parse_query
instead:
add_action( 'parse_query', function() {
add_rewrite_rule( 'go/([^/]+)/?$', 'index.php?redirect_to=$matches[1]', 'top' );
add_rewrite_tag( "%redirect_to%", '([^&]+)' );`
} );
Reason: init
is too early, query_vars haven’t been set yet. wp_head
is too late, no can redirect at that point.