I am having this same issue and am at my wits end.
I’ve cleared the cache folder and the sessions folder.
I ran the above script.
I truncated the core_url_rewrite table.
I turned off redirect to base url.
I turned of url rewrites.
I changed all domain name references in core_config_data
I cleared cookies and made sure cookie timeout was sufficient to compensate for server/browser time differences.
I’ve checked my .htaccess file for redirects.
I’ve done everything suggested everywhere, yet still the site redirects from the new subdomain to the original main domain.
I am at a loss as to how to stop magento from incorrectly redirecting me.
I need help.