Disable redirect after product add to basket

If you look into the cart controller app/code/core/Mage/Checkout/controllers/CartController.php your will find the function _goBack. This is where the return url is decided by Magento.

protected function _goBack()
{
    $returnUrl = $this->getRequest()->getParam('return_url');
    if ($returnUrl) {

        if (!$this->_isUrlInternal($returnUrl)) {
            throw new Mage_Exception('External urls redirect to "' . $returnUrl . '" denied!');
        }

        $this->_getSession()->getMessages(true);
        $this->getResponse()->setRedirect($returnUrl);
    } elseif (!Mage::getStoreConfig('checkout/cart/redirect_to_cart')
        && !$this->getRequest()->getParam('in_cart')
        && $backUrl = $this->_getRefererUrl()
    ) {
        $this->getResponse()->setRedirect($backUrl);
    } else {
        if (($this->getRequest()->getActionName() == 'add') && !$this->getRequest()->getParam('in_cart')) {
            $this->_getSession()->setContinueShoppingUrl($this->_getRefererUrl());
        }
        $this->_redirect('checkout/cart');
    }
    return $this;
}

The section your are looking for is the call to _getRefererUrl this happens when you are not setting the return url as a parameter and not using the default redirect to cart option.

Inside the function _getRefererUrl the referrer url is checked to see if it is an internal url, when it is not internal than the base url is used.

I would suggest that either your referrer url is external or there is something wrong with the check.

Have a look at Mage_Core_Controller_Varien_Action::_isUrlInternal to debug if the url is internal or not.

Problem was that _isUrlInternal was failing because of having the port in the base url


In addition to david-manners answer, you as well may have issues with your web/unsecure/base_url & web/secure/base_url being set correctly without ports - but your actual app vhost (apache/nginx) listening on some port other than 80/443, e.g. when running behind varnish.

This will result in \Mage_Core_Helper_Url::getCurrentUrl, used e.g. for adding the base64 encoded query params - decoded and used by _getRefererUrl having the 'non-default' port as part of the url. (e.g. http://www.domain.com:81/your-url.html)

As a result Mage_Core_Controller_Varien_Action::_isUrlInternal returns false...

For further reference, see
http://erikeng.se/post/magento-behind-varnish.html

A clean and good solution is described in
https://serverfault.com/questions/318151/how-to-set-php-server-port-var-to-80-behind-varnish