@lasclients Hello, you should debug the redirections in this case. Here's what you can do in Magento 2:
If you face an unexpected 301 or 302 redirect in Magento 2 and you don't know why it happens or what code causes it, you can easily find this out by temporarily editing the following files:
/vendor/magento/framework/HTTP/PhpEnvironment/Response.php
/var/www/html/m2_35ee/vendor/magento/framework/Controller/Result/Redirect.php
Open Response.php and add the following line to the beginning of the setRedirect function:
var_dump($url); \Magento\Framework\Debug::backtrace(false, true, false); exit();
Example:
public function setRedirect($url, $code = 302)
{
var_dump($url); \Magento\Framework\Debug::backtrace(false, true, false); exit();
$this->setHeader('Location', $url, true)
->setHttpResponseCode($code);
return $this;
}
Now you open the second Redirect.php file and add this:
var_dump($this->url); \Magento\Framework\Debug::backtrace(false, true, false); exit();
After each line containing:
$this->url =
Example:
public function setRefererUrl()
{
$this->url = $this->redirect->getRefererUrl();
var_dump($this->url); \Magento\Framework\Debug::backtrace(false, true, false); exit();
return $this;
}
public function setRefererOrBaseUrl()
{
$this->url = $this->redirect->getRedirectUrl();
var_dump($this->url); \Magento\Framework\Debug::backtrace(false, true, false); exit();
return $this;
}
public function setUrl($url)
{
$this->url = $url;
var_dump($this->url); \Magento\Framework\Debug::backtrace(false, true, false); exit();
return $this;
}
public function setPath($path, array $params = [])
{
$this->url = $this->urlBuilder->getUrl($path, $this->redirect->updatePathParams($params));
var_dump($this->url); \Magento\Framework\Debug::backtrace(false, true, false); exit();
return $this;
}
Save the corresponding changes and open a page that causes an unexpected redirect. You should see a debug backtrace with the information about the code line causing the redirect.
If you don't see it, it means that the redirect is not caused by Magento code, but the webserver settings, or the third-party module code that uses not-recommended Magento programming practices.
Hope this helps!