11

We are having the strangest Redirection problem on a Magento site. We copied the sites contents from another Magento site to a new URL. We have done this in the past with no problems but for some reason this one redirects to the old website as soon as you try to load the page, any page.

Below are all the steps I have done so far in my quest to Debug this pain...

www.Old-Domain.com = The Old site URL that we moved away from

www.NEW-Domain.com = The new site that we have copied Magento over to.

Steps done so far to try an resolve redirection issue:

  • Searched whole MySQL database (All tables) for the string www.Old-Domain.com and made sure there was none that could be causing the Redirection to happen.
  • Updated Database Table core_config_data columns web/unsecure/base_url and web/secure/base_url to the new sites URL www.NEW-Domain.com
  • cleared any Cache files from /var/cache/ in the Magento Root
  • Checked Server's cache folders to make sure files weren't being cached there due to permission or other error.
  • Inspected .htaccess file to make sure it wasn't happening there
  • Inspected index.php file as well and printed out some content followed by an exit() call and progressively moved it down the page until the point that the Redirection occurs. It is the very last line where this is called Mage::run($mageRunCode, $mageRunType); once the page loads and gets to this line, I am immediately Redirected to our old website URL!

Any ideas?

2
  • Debug for index.php. What are the variables $mageRunCode and $mageRunType filled with on one of your normal running sites and how do they compare to the redirecting site? Commented Sep 27, 2014 at 20:15
  • @jason : is your issue solved?
    – zus
    Commented Nov 13, 2017 at 6:21

12 Answers 12

20

Or the oldest one in the book, your file/directory permissions are out of whack causing Magento to write to the system /tmp folder which means config information is cached till you reboot the whole server or go delete the Magento cache out of the system /tmp folder.

Issue is described here Can't change Magento base URL, stuck in cache

Only including this because the server's cache folders doesn't necessarily translate into /tmp

Also, it isn't noted if this is a different domain on the same server, but local.xml needs a change of database credentials in addition to not naming the backup copy of local.xml something like backup-local.xml which would load it previous to your changed file (Magento loads all .xml files in app/etc)

Also, if this was a direct copy of all files, and the compiler was enabled, disable it and clear its code store.

1
  • In regards to the local.xml file - download a copy to your computer, remove it from the server, then clear folders in var/cache and var/sessions. Trying to load the site should give an error. Make changes to the local.xml on your computer, then upload to server and clear cache/sessions folders again. Try loading site with changes. Duplicates of local.xml (even renamed) can be hazardous.
    – Steven J
    Commented Aug 4, 2017 at 16:08
5

I just had this problem, after trying everything listed above and on several other SO answers i discovered there is more than one base_url definition in the core_config_data table

if you run

select * from core_config_data where path like '%base_url%'

You should see all of the definitions the scope was different on this definition and was overriding the default which i had already changed.

2
  • 1
    Thanks for posting, hopefully this will help someone someday who searches and finds this question. I just want to mention that in my particular case there is only 1 in the database so perhaps because my install was a single scope it only had one which means this didn't help in my case. To be honest I can't remember how I fixed mine which I should of posted the result here when I did a while back! Anyways i'm sure this will help someone and is something to check if the issue arises for sure, thanks for sharing =)
    – JasonDavis
    Commented Feb 27, 2015 at 5:32
  • I spoke to soon, I do know what the solution for mine was...It seems somehow the DB result/data was being cached on our server so after a half day or so once the c ache expiured I assume, then it all worked as expected! To this day I do not know why or what was causing the DB to cache the value. We had Varness on the original server but the new server with the problem did not have Varness cache so who knows but in any case it was eff something on our server caching the data!
    – JasonDavis
    Commented Feb 27, 2015 at 5:35
3

I had the same problem

Try what i did

STEP 1 : log from SSH and delete cache with this command:

rm -rf /var/tmp/magento/*

STEP 2 – RESET FILE PERMISSIONS

To make sure that all javascript files, CSS, and images load correctly, you should reset the file permissions to the recommended settings for your new server.

Run the following commands from your Magento root directory (e.g. public_html):

find . -type d -exec chmod 755 {} \;
find . -type f -exec chmod 644 {} \;

This will reset permissions for all files to CHMOD 644, and CHMOD 755 for directories.

PS: In order to use the Magento Connect Manager you may have to reset the PEAR configuration settings. To do this, simply remove the file downloader/pearlib/pear.ini, and a new one will be created automatically.

PS 2 : Do not forget to check the .htaccess file if has any redirect to old domain name

2

Besides what you already tried, I can think of the following possible reasons:

  • Magento's configuration cache is stored in a different backend than files in /var/cache, for example memcache or redis. Check the file app/etc/local.xml and look if there is an entry like

    <cache>
        <backend>memcached</backend>
    

    with anything else than files between the backend tags. Look up how to clean the cache for your specific backend or if you use the excellent n98-magerun command line tool, type n98-magerun cache:flush in your Magento root directory. You can get Magerun here: https://github.com/netz98/n98-magerun

  • The base_url is defined somewhere else with higher precedence than the database. This could be app/etc/local.xml or any other xml file in app/etc. Did you do a search for the old domain in the code base? Try running rgrep old-domain * in the Magento root directory.

1
  • Bullet point two - anything using a configuration path in core_config_data can also be defined in any local.xml and a good observation as I've seen people try to hack Magento into functioning by doing stuff like this. It gets forgotten a year or two later. Commented Sep 27, 2014 at 19:58
2

Solution #1

Restart your webserver.

Ubuntu: systemctl restart apache2

Solution #2

Check if your database is set correctly in app/etc/env.php I've cloned a shop and imported my database dump but I totally forgot to change the database to my new database in env.php

1

this works for me, I think need to clear cash,

<?php 
require_once 'app/Mage.php';
$app = Mage::app();

echo "<pre-->";
if($app != null) {
        echo "The app was initialized.\n";
        $cache = $app->getCache();
        if($cache != null) {
                echo "The cache is not empty. Clean it.\n";
                $cache->clean();
        }
}
exit;
?>

http://www.w3bdeveloper.com/how-to/magento-redirects-to-old-url-after-moving-to-new-domain-solved/

0
0

I also had this problem. I already deleted all the files in the var/cache, var/session and changed the base_url in the table core_config_data to the new URL. But still the site redirected to the old site.

I had forgotten to edit the database detail (username, password, and dbname) in config.xml in folder app/etc/:

   <username><![CDATA[myusername]]></username>
   <password><![CDATA[mypassword]]></password>
   <dbname><![CDATA[mydbname]]></dbname>

Now my site is running well after I edited config.xml.

0

I don't recall having to do this for previous versions of Magento, but certainly, since implementing EE 1.14.3.3 I have to reindex URLs to resolve this issue.

0

Oh Yes !

For me finally what worked was :

php shell/indexer.php --reindexall via ssh.

It appears, quite logically so, that after the files have been copied over from a previous live installation the urls still point to the old store and hence have to be reindexed. But because the admin page in this case will also be inaccessible, the reindex will have to be via ssh

Hope it works for others too !

1
  • Or use magerun (./n98-magerun.phar index:reindex:all)
    – Black
    Commented Sep 18, 2018 at 14:00
0

If you are using Google Chrome try using a different browser (Firefox, Edge etc) before you try any of these other methods and you may find that the addresses work as you intend. Chrome appears to do some kind of caching. I wasted at least an hour of my time going through configuration files and testing things.

0

I also had this problem. I already deleted all the files in the var/cache, var/session and changed the base_url in the table core_config_data to the new URL. But still the site redirected to the old site.

I had forgotten to edit the database detail (username, password, and dbname) in config.xml in folder app/etc/:

yes, this one helped me, after i deleted the cache, it worked for me

0

Check also configuration value for web/secure/base_link_url

select * from core_config_data where path like '%base%_url%';

Or simply look for configuration values with the old URL in value:

select * from core_config_data where value like '%your-old.url.com%';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.