Recently, we had to setup a staging site for one of our customers. He runs one of the most popular online pharmacies in New Zealand. Here are some of the solutions we tried for the redirection problem. This is where Magento continues to redirect the website to the old URL. When you see this happening, try the following solutions.

1) Update base URL and secure base URL in the core_config_data table

2) TRUNCATE core_session table

3) Run the following Query in PHPMyAdmin

SET FOREIGN_KEY_CHECKS=0;
UPDATE `core_store` SET store_id = 0 WHERE code='admin';
UPDATE `core_store_group` SET group_id = 0 WHERE name='Default';
UPDATE `core_website` SET website_id = 0 WHERE code='admin';
UPDATE `customer_group` SET customer_group_id = 0 WHERE customer_group_code='NOT LOGGED IN';
SET FOREIGN_KEY_CHECKS=1;

4) Clear /var/cache/* and /var/session/* folders

5) Clear your Browser Cache/Cookies

6) CHMOD 777 the var directory to avoid having the system write in /tmp folder of your Server

7) Check your .htaccess file and make sure the URL there is changed especially if you have installed Magento in sub-folders

8) Make sure you clear APC cache

9) Make sure you have turned off Magento Compilation before backing up database and files

10) If you have set up sessions to be stored in database, you need to clear core

DELETE FROM core_session WHERE session_expires < UNIX_TIMESTAMP()

If all else fails, pray to God that you would find the right solution