In my case I installed a magento on my localhost on /var/www/magento to be accessible trough 127.0.0.1/magento.
After a while I just decided to access my site from another computer on my local network. So this time I entered 192.168.1.4/magento (IP of my first computer with magento installed locally). It quickly redirected me to localhost/magento!
To fix that I entered the database on my first computer and entered:
Remember two things:
- The new address must end with a slash character ‘/’ or you gonna see an ugly white theme on your site!
- If you are moving your magento to a new server with completely different configuration, you need to open your <magento installation path>/app/etc/local.xml file and edit the <connection> tag to modify database connection settings (i.e. username, password).
Hope it helps!