2

EDIT:

This seems to have been caused by my CREARESEO extension. I had to uninstall to find that out since disabling the extension fooled me into thinking it was something else. I am working on locating the file that is interrupting Magento's default redirect, any guidance would be greatly appreciated.

Original Post

How can I debug product redirect?

I am tracking products in Google Shopping by appending ?utm_source=google_shopping to the product URL. The problem is that for some reason Magento will not allow URL parameters on product URLs.

If my product url is /product-one.html?this=parameter it 301 redirects to /product-one.html.

EDIT: This only happens on product pages. If I append category or CMS page urls with URL parameters they work fine. That said, if my category URL is /recipes and I type the old URL of /recipes.html?this=parameter "?this=parameter" is lost.

I have disabled my SEO extensions and when I do a var_dump of $request on line 202 of /mage/core/controller/varien/router/standard.php it knows that the requested URL has the parameters but it chooses not to preserve them in the redirect.

    object(Mage_Core_Controller_Request_Http)#35 (26) {
      ["_originalPathInfo":protected]=>
      string(33) "/cinnamon.html"
      ["_storeCode":protected]=>
      NULL
      ["_requestString":protected]=>
      string(33) "/cinnamon.html"
      ["_rewritedPathInfo":protected]=>
      array(5) {
        [0]=>
        string(7) "catalog"
        [1]=>
        string(7) "product"
        [2]=>
        string(4) "view"
        [3]=>
        string(2) "id"
        [4]=>
        string(4) "9736"
      }
      ["_requestedRouteName":protected]=>
      NULL
      ["_routingInfo":protected]=>
      array(0) {
      }
      ["_route":protected]=>
      string(13) "ajaxaddtocart"
      ["_directFrontNames":protected]=>
      NULL
      ["_controllerModule":protected]=>
      string(17) "FME_Ajaxaddtocart"
      ["_isStraight":protected]=>
      bool(false)
      ["_beforeForwardInfo":protected]=>
      array(0) {
      }
      ["_paramSources":protected]=>
      array(2) {
        [0]=>
        string(4) "_GET"
        [1]=>
        string(5) "_POST"
      }
      ["_requestUri":protected]=>
      string(37) "/catalog/product/view/id/9736?this=ok"
      ["_baseUrl":protected]=>
      string(0) ""
      ["_basePath":protected]=>
      NULL
      ["_pathInfo":protected]=>
      string(35) "/ajaxaddtocart/product/view/id/9736"
      ["_params":protected]=>
      array(1) {
        ["id"]=>
        string(4) "9736"
      }
      ["_rawBody":protected]=>
      NULL
      ["_aliases":protected]=>
      array(1) {
        ["rewrite_request_path"]=>
        string(32) "cinnamon.html"
      }
      ["_dispatched":protected]=>
      bool(true)
      ["_module":protected]=>
      string(13) "ajaxaddtocart"
      ["_moduleKey":protected]=>
      string(6) "module"
      ["_controller":protected]=>
      string(7) "product"
      ["_controllerKey":protected]=>
      string(10) "controller"
      ["_action":protected]=>
      string(4) "view"
      ["_actionKey":protected]=>
      string(6) "action"
    }

I modified the file mentioned above in hopes of forcing the parameters to be inherited by the rewritten rule to no avail.

 $requestedURL=$request->getRequestUri();
     $urlAliases=$request->getAliases();
     $urlAlias=$urlAliases['rewrite_request_path'];
     $parametersOfRequestedURL=strstr($requestedURL,"?",false);
     if($parametersOfRequestedURL){
         echo $newRequestURL=$urlAlias.$parametersOfRequestedURL;
         $request->setRequestUri($newRequestURL);
         var_dump($request);
         die;
         //$request->setRequestUri();
     }

Removed HTACCESS as it seems to not be a part of the problem. Will provide if requested.

  • Try commenting out this section <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_URI} !^/subdomain/piwik/ ... and retest – Renon Stewart Oct 9 '14 at 16:02
  • I have. It seems to be controlled by Magentos URL rewrite. I have disabled my SEO extensions and when I do a var_dump of $request on line 202 of /mage/core/controller/varien/router/standard.php it knows that the requested URL has the parameters but it chooses not to preserve them in the redirect. – TylersSN Oct 9 '14 at 16:37
  • What magento version are you using? – Renon Stewart Oct 9 '14 at 16:41
  • @r.s Magento 1.7 (see tags). – TylersSN Oct 9 '14 at 17:06
  • I just test on 1.7 and not having that issue – Renon Stewart Oct 9 '14 at 17:08
3

I had the same issue with the CREARESEO extension. I fixed it by doing the following:

Open /app/code/community/Creare/CreareSeoCore/Model/Observer.php

Find:

    public function forceProductCanonical(Varien_Event_Observer $observer)
{
    if (Mage::getStoreConfig('catalog/seo/product_canonical_tag') && !Mage::getStoreConfig('product_use_categories'))
    {
        if (Mage::getStoreConfig('creareseocore/defaultseo/forcecanonical')) {
            // check for normal catalog/product/view controller here
            if(!stristr("catalog",Mage::app()->getRequest()->getModuleName()) && Mage::app()->getRequest()->getControllerName() != "product") return;
            $product = $observer->getEvent()->getProduct();
            $url = $product->getUrlModel()->getUrl($product, array('_ignore_category'=>true));
            if(Mage::helper('core/url')->getCurrentUrl() != $url){
                Mage::app()->getFrontController()->getResponse()->setRedirect($url,301);
                Mage::app()->getResponse()->sendResponse();
            }
        }
    }
}

And replace with:

    public function forceProductCanonical(Varien_Event_Observer $observer)
{
    if (Mage::getStoreConfig('catalog/seo/product_canonical_tag') && !Mage::getStoreConfig('product_use_categories'))
    {
        if (Mage::getStoreConfig('creareseocore/defaultseo/forcecanonical')) {
            // check for normal catalog/product/view controller here
            if(!stristr("catalog",Mage::app()->getRequest()->getModuleName()) && Mage::app()->getRequest()->getControllerName() != "product") return;
            $product = $observer->getEvent()->getProduct();
            $url = $product->getUrlModel()->getUrl($product, array('_ignore_category'=>true));
            // if there are GET parameters, add them to the url
            if($_GET) {
                $params = '?' . http_build_query($_GET, '', '|');
                $url .= $params;
            }
            if(Mage::helper('core/url')->getCurrentUrl() != $url){
                Mage::app()->getFrontController()->getResponse()->setRedirect($url,301);
                Mage::app()->getResponse()->sendResponse();
            }
        }
    }
}

Cheers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.