Magento 1.6.1-从购物车中删除重定向到主页(运行Varnish)



我在Magento 1.6.1上遇到了一个非常奇怪的问题。

我们有三个平台,DEV,TST,LIVE(当前活跃的运行网站)。

我们也在现场前运行Varnish。

问题是,在LIVE网站上,当你从购物车中删除某些内容(使用删除按钮)时,你总是会被重定向到主页。如果通过将项目数量设置为0来删除项目,则可以。

这个问题不会出现在DEV或TST上的同一个代码库上。

这可能是瓦尼什的干扰吗?有什么建议吗?

您是否在开发/暂存站点上运行Varnish?听起来不像你。

我猜你的Magento的Varnish模块有一个观察者来检测购物车是否有任何内容(即,看看你是否真的有一个独特的会话),但当你清空购物车时,这个观察者会向Varnish发送nocache头,Varnish会返回一个新的(缓存的、非cookie的)响应,并将你带回主页。

听起来你的Varnish模块就是原因。

拆下Varnish及其相关的Magento模块,然后重新测试。这似乎是一个很容易排除的方法。

当我将本地环境配置为在Nginx面前使用Varnish时,有一件事让我印象深刻,那就是应用程序重定向开始起作用。从产品视图添加用于比较的产品将我重定向到基本URL,而不是返回到产品视图(refer)。所以我开始深入研究核心,看看到底发生了什么

app/code/core/Mage/Core/Controller/Varien/Action.php:773

_getRefererUrl方法在请求URI中或从请求头中查找任何referer URL。由于某种原因,$refererUrl没有作为_isUrlInternal传递,这使得它回落到基本URL。

/**
 * Identify referer url via all accepted methods (HTTP_REFERER, regular or base64-encoded request param)
 *
 * @return string
 */
protected function _getRefererUrl()
{
    $refererUrl = $this->getRequest()->getServer('HTTP_REFERER');
    if ($url = $this->getRequest()->getParam(self::PARAM_NAME_REFERER_URL)) {
        $refererUrl = $url;
    }
    if ($url = $this->getRequest()->getParam(self::PARAM_NAME_BASE64_URL)) {
        $refererUrl = Mage::helper('core')->urlDecode($url);
    }
    if ($url = $this->getRequest()->getParam(self::PARAM_NAME_URL_ENCODED)) {
        $refererUrl = Mage::helper('core')->urlDecode($url);
    }
    $refererUrl = Mage::helper('core')->escapeUrl($refererUrl);
    if (!$this->_isUrlInternal($refererUrl)) {
        $refererUrl = Mage::app()->getStore()->getBaseUrl();
    }
    return $refererUrl;
}

app/code/core/Mage/Core/Controller/Varien/Action.php:799

这里Magento正在寻找(基本URL)字符串的位置http://domain.com/中(引用者URL)http://domain.com:8080/any/url.html,由于Nginx正在侦听的端口号(在Varnish后面),将永远找不到它。

/**
 * Check url to be used as internal
 *
 * @param   string $url
 * @return  bool
 */
protected function _isUrlInternal($url)
{
    if (strpos($url, 'http') !== false) {
        /**
         * Url must start from base secure or base unsecure url
         */
        if ((strpos($url, Mage::app()->getStore()->getBaseUrl()) === 0)
            || (strpos($url, Mage::app()->getStore()->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, true)) === 0)
        ) {
            return true;
        }
    }
    return false;
}

app/code/core/Mage/Core/Helper/Url.php:37

这个端口号是(出于某种奇怪的原因)在Magento中构建当前URL时添加的。

/**
 * Retrieve current url
 *
 * @return string
 */
public function getCurrentUrl()
{
    $request = Mage::app()->getRequest();
    $port = $request->getServer('SERVER_PORT');
    if ($port) {
        $defaultPorts = array(
            Mage_Core_Controller_Request_Http::DEFAULT_HTTP_PORT,
            Mage_Core_Controller_Request_Http::DEFAULT_HTTPS_PORT
        );
        $port = (in_array($port, $defaultPorts)) ? '' : ':' . $port;
    }
    $url = $request->getScheme() . '://' . $request->getHttpHost() . $port . $request->getServer('REQUEST_URI');
    return $url;
}

使重定向再次工作

在不更改应用程序的情况下,您的Web服务器(Nginx)需要在端口80(或443)上侦听,同时仍保持Varnish在其前面。这可以通过使用iptables来实现。

相关内容

最新更新