cancel
Showing results for 
Search instead for 
Did you mean: 

Magento Redirect Loses URL Querystring

SOLVED

Magento Redirect Loses URL Querystring

I've just been on the phone with Adwords and they've told me my gclid url query string is not working properly.

 

So I did some digging and found this stackexchange question / answer that really looks like it should solve my problems:

https://stackoverflow.com/questions/26629722/magento-category-redirect-cuts-off-the-querystring-of-a...

 

The thing is, the answer says to put the following code in Request.php

    $queryString = $this->_getQueryString();
    if ($queryString) {
        $targetUrl .= '?'.$queryString;
    }

 

When I look in Request.php - that code is already there (magento 1.9.0.1) - but when I make a request on a URL with a query string to a page that is redirected by magento (such as one of my top menu pages), no query string is appended to the redirected to url.

 

Can someone please help me or point me in the right direction?

 

Thank you!!

7 REPLIES

Re: Magento Redirect Loses URL Querystring

Please can someone help me?

I have looked everywhere for a solution Smiley Sad


I really don't even know where to begin!

Re: Magento Redirect Loses URL Querystring

I verified this solution works. This code is not in magento 1.9, did you add it correctly? you have to add it before _sendRedirectHeaders method.

Re: Magento Redirect Loses URL Querystring

KuafuSoft you are the best!!

 

For some reason in my install (I have patched it with some of the magento patches though?) the _processRedirectOptions() looks like this :

 

 

    protected function _processRedirectOptions()
    {
        $isPermanentRedirectOption = $this->_rewrite->hasOption('RP');

        $external = substr($this->_rewrite->getTargetPath(), 0, 6);
        if ($external === 'http:/' || $external === 'https:') {
            $destinationStoreCode = $this->_app->getStore($this->_rewrite->getStoreId())->getCode();
            $this->_setStoreCodeCookie($destinationStoreCode);
            $this->_sendRedirectHeaders($this->_rewrite->getTargetPath(), $isPermanentRedirectOption);
        }

        $targetUrl = $this->_request->getBaseUrl() . '/' . $this->_rewrite->getTargetPath();

        $storeCode = $this->_app->getStore()->getCode();
        if (Mage::getStoreConfig('web/url/use_store') && !empty($storeCode)) {
            $targetUrl = $this->_request->getBaseUrl() . '/' . $storeCode . '/' . $this->_rewrite->getTargetPath();
        }

        if ($this->_rewrite->hasOption('R') || $isPermanentRedirectOption) {
            $this->_sendRedirectHeaders($targetUrl, $isPermanentRedirectOption);
        }

        $queryString = $this->_getQueryString();
        if ($queryString) {
            $targetUrl .= '?' . $queryString;
        }

        $this->_request->setRequestUri($targetUrl);
        $this->_request->setPathInfo($this->_rewrite->getTargetPath());

        return $this;
    }

 

So you can see the $queryString code fix in the file procedure.

But you are right - it was not in the correct place!

So I've moved it to that place and now it works.

 

 

Thank you again!!

Re: Magento Redirect Loses URL Querystring

I've inserted the query code in right place but it still loses querystring. I used Magento 1.9.1. Do I have to do another modification?? Please helppppp

Re: Magento Redirect Loses URL Querystring

Hiya Tuan,

 

Please paste the code snippet and I'll try to help!

 

Smiley Happy

Re: Magento Redirect Loses URL Querystring

More about......Query String

 

Rino

Re: Magento Redirect Loses URL Querystring

Hi Ioginid

Please find code snippet below

protected function _processRedirectOptions()
    {
        $isPermanentRedirectOption = $this->_rewrite->hasOption('RP');

        $external = substr($this->_rewrite->getTargetPath(), 0, 6);
        if ($external === 'http:/' || $external === 'https:') {
            $destinationStoreCode = $this->_app->getStore($this->_rewrite->getStoreId())->getCode();
            $this->_setStoreCodeCookie($destinationStoreCode);
            $this->_sendRedirectHeaders($this->_rewrite->getTargetPath(), $isPermanentRedirectOption);
        }

        $targetUrl = $this->_request->getBaseUrl() . '/' . $this->_rewrite->getTargetPath();

        $storeCode = $this->_app->getStore()->getCode();
        if (Mage::getStoreConfig('web/url/use_store') && !empty($storeCode)) {
            $targetUrl = $this->_request->getBaseUrl() . '/' . $storeCode . '/' . $this->_rewrite->getTargetPath();
        }

        if ($this->_rewrite->hasOption('R') || $isPermanentRedirectOption) {
			$queryString = $this->_getQueryString();
        	if ($queryString) {
            	$targetUrl .= '?' . $queryString;
        	}
            $this->_sendRedirectHeaders($targetUrl, $isPermanentRedirectOption);
        }
		$queryString = $this->_getQueryString();
        	if ($queryString) {
            	$targetUrl .= '?' . $queryString;
        	}
        

        $this->_request->setRequestUri($targetUrl);
        $this->_request->setPathInfo($this->_rewrite->getTargetPath());

        return $this;
    }

Do I do right? Please help