Categories


Archives


Recent Posts


Categories


Magento Base URL Redirect

astorm

Frustrated by Magento? Then you’ll love Commerce Bug, the must have debugging extension for anyone using Magento. Whether you’re just starting out or you’re a seasoned pro, Commerce Bug will save you and your team hours everyday. Grab a copy and start working with Magento instead of against it.

Updated for Magento 2! No Frills Magento Layout is the only Magento front end book you'll ever need. Get your copy today!

Magento’s configuration includes a hard coded field for the base site URL. This often creates headaches when a user migrates a system to a new server/URL, but hasn’t updated the URL entries in the core_config_data table. These headaches are compounded by

  1. The fact that the entries in core_config_data are cached by Magento
  2. Most web browsers aggressively cache HTTP header based redirects
  3. If a user didn’t update core_config_data, there’s also a good chance they’re the sort of user who wouldn’t update their web server configuration

Whenever I’m facing a problem like this with a system, I like to hop to the following code point

#File: app/code/core/Mage/Core/Controller/Varien/Front.php
    if (isset($uri['scheme']) && $uri['scheme'] != $request->getScheme()
        || isset($uri['host']) && $uri['host'] != $request->getHttpHost()
        || isset($uri['path']) && strpos($requestUri, $uri['path']) === false
    ) {            
        Mage::app()->getFrontController()->getResponse()
            ->setRedirect($baseUrl, $redirectCode)
            ->sendResponse();
        exit;
    }

This complicated conditional statement is where Magento performs a redirect if the request URL doesn’t match the base url. Some quick var_dump/exit debugging before the call to sendResponse can be a nice sanity check.

Copyright © Alana Storm 1975 – 2023 All Rights Reserved

Originally Posted: 20th January 2014

email hidden; JavaScript is required