I am need of making a change to the Magento function _checkBaseUrl found within:


As best practice I am trying to extend it with my own module so I am not editing the core code and files but it is not working. If I make the change in the core file i get the desired response but when using this it doesn't work. My module is showing up as Enabled in Configuration > Advanced > Advanced

Files are as below:


<?xml version="1.0" encoding="UTF-8"?>


<?xml version="1.0"?>
                         <Me_Coreextend before="Mage_Core">Me_Coreextend</Me_Coreextend>


I am including only the _checkBaseUrl function in this file not the whole contents of app/code/core/Mage/Core/Controller/Varien/Front.php - is this correct? (I have tried to include it all as well but that still doesn't work either)

class Me_Coreextend_Controller_Varien_Front extends Mage_Core_Controller_Varien_Front
    protected function _checkBaseUrl($request)
        // custom changes...

Is there anything I am doing wrong?

  • 1
    That method is used to extend "controllers", you are not dealing with one. My guess would be to get that file in local code pool, but maybe there are better approaches for this.
    – Prateek
    Commented Sep 5, 2015 at 14:12
  • Yes, this is correct. I was wrongly mistaking the existing Controller folder. Copying the one file into my local pool did the trick.
    – odd_duck
    Commented Sep 7, 2015 at 13:09
  • 1
    May be event controller_front_init_routers is worth looking at.
    – MagePsycho
    Commented Jan 15, 2016 at 20:24
  • @odd_duck please add the solution as an answer to the question
    – Alex Dinca
    Commented Jan 16, 2016 at 14:33

1 Answer 1


You cannot rewrite the class Mage_Core_Controller_Varien_Front because it is not initiating by any of Magento factory methods which actually allow us to have rewrite concept.

Front controller is actually initiating in Mage_Core_Model_App::_initFrontController() and that method looks like this:

protected function _initFrontController()
    $this->_frontController = new Mage_Core_Controller_Varien_Front();
    Mage::register('controller', $this->_frontController);
    return $this;

Since it uses regular $this->_frontController = new Mage_Core_Controller_Varien_Front(); class instance intialization, you cannot use any kind of rewrite techniques which is offering by Magento to rewrite this core class.

3 options are there for you :

1. Use CodePool Technique

Create new class Mage_Core_Controller_Varien_Front in either local or community codepool and make your changes there.

2. Use Events Which Are Triggering In Prior to _checkBaseUrl() Function

There are two events happending in prior to invoking Mage_Core_Controller_Varien_Front::_checkBaseUrl(). They are :

  1. controller_front_init_before
  2. controller_front_init_routers

You can use any of these event for your changes if possible.

3. Change Response Object As Per Your Need

If you check Mage_Core_Controller_Varien_Front::_checkBaseUrl(), you can see that it validates whether requested uri and base url of Magento instance are same or not. If not, then it will redirect request to the corresponding external url.

So later the case, Magento invokes response object to do this redirection. By default, this response object is Mage_Core_Controller_Request_Http. So instead of this you can use your own response object. All you need to do is specify this in your index.php file, while invoking Mage::run().

Mage::run($mageRunCode, $mageRunType, array('response' => YOUR_CUSTOM_CLASS);

Here Magento will use YOUR_CUSTOM_CLASS instead of default response object and hence you can do some customization through your custom class.

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.