I think there is more than one way to do what you need, and this is the one I used near the top of wp-config.php:
<?php
/**
* The base configurations of the WordPress.
*
* @package WordPress
*/
/*-either-*/
/** @ root/wp-config.php: /*toggle on/off*
define('WP_HOME','https://domain.com');
define('WP_SITEURL','https://domain.com');
/*-or-*/
/** @ root/wp-config.php: /*toggle on/off*
define('WP_HOME','https://www.domain.com');
define('WP_SITEURL','https://www.domain.com');
/*-end-*/
Adding a single slash to make /** @ root/wp-config.php: /*toggle on/off*
look like /** @ root/wp-config.php: /*toggle on/off*/
will turn either pair of lines on, then go back and disable that after refreshing your browser a few times, and then go to Dashboard > Settings > General and save the results you see there.
If this might seem easier, I think this can do the same from the top of functions.php in your theme:
<?php
/*-either-*/
/* @ theme/functions.php /*toggle on/off*
update_option('siteurl','https://domain.com');
update_option('home','https://domain.com');
/*-or-*/
/* @ theme/functions.php /*toggle on/off*
update_option('siteurl','https://www.domain.com');
update_option('home','https://www.domain.com');
/*-end-*/
Here is a related article that is definitely worth reading, imo:
https://www.internetmarketingninjas.com/blog/search-engine-optimization/301-redirects/
And for a local opinion on the matter:
https://www.ads-software.com/support/topic/i-think-bulletproof-just-stopped-me-from-damaging-my-own-site?replies=40#post-6233626