302 redirects in Magento, trying to fix
-
Hi all, I'm assigned a site in Magento. After the first craw, we found almost 15k 302 redirects.
A sample URL ends with this /stores/store/switch/?SID=qdq9mf1u6afgodo1vtvk0ucdpb&___from_store=default&___store=german&uenc=aHR0cHM6Ly9qdWljeWZsdXRlcy5jb20vP19fX3N0b3JlPWdlcm1hbg%2C%2C
And they are currently 302 redirecting to the homepage as well as other main pages and also product pages it seems.
Some of these point to account pages where customers log in. Probably best for me to de-index those so no issues there.
But I'm worried about the 302 redirects to public pages.
The extension we have installed is SEO Suite Ultimate by MageWorx.
Does anyone here have experience here specifically and how did you fix it?
Thanks,
JC
-
It turned out to be a language extension. We took it out and fixed everything except for a couple of links. I'm opening a new question for those. Thanks for all your help!
-
Look at the template, as this is the likely culprit making links to these 302 redirects. If they are not required, simply remove any references to the link on your template?
If they are necessary links as you say, customer login etc - add a nofollow tag and de-index the page.
Ensure you have self-referencing canonical tags on the pages with lots of parameters.
You could also remove the a tag to something less SEO friendly to reduce your potential crawl budget ensuring that your non-vital (product/category) pages exhume more importance.
If you have so many links/pages, they will get lost within all the nonsense.
-
@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!
Got a burning SEO question?
Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.
Browse Questions
Explore more categories
-
Moz Tools
Chat with the community about the Moz tools.
-
SEO Tactics
Discuss the SEO process with fellow marketers
-
Community
Discuss industry events, jobs, and news!
-
Digital Marketing
Chat about tactics outside of SEO
-
Research & Trends
Dive into research and trends in the search industry.
-
Support
Connect on product support and feature requests.
Related Questions
-
Our clients Magento 2 site has lots of obsolete categories. Advice on SEO best practice for setting server level redirects so I can delete them?
Our client's Magento website has been running for at least a decade, so has a lot of old legacy categories for Brands they no longer carry. We're looking to trim down the amount of unnecessary URL Redirects in Magento, so my question is: Is there a way that is SEO efficient to setup permanent redirects at a server level (nginx) that Google will crawl to allow us at some point to delete the categories and Magento URL Redirects? If this is a good practice can you at some point then delete the server redirects as google has marked them as permanent?
Technical SEO | | WillyGx0 -
Our clients Magento 2 site has lots of obsolete categories. Advice on SEO best practice for setting server level redirects so I can delete them?
Our client's Magento website has been running for at least a decade, so has a lot of old legacy categories for Brands they no longer carry. We're looking to trim down the amount of unnecessary URL Redirects in Magento, so my question is: Is there a way that is SEO efficient to setup permanent redirects at a server level (nginx) that Google will crawl to allow us at some point to delete the categories and Magento URL Redirects? If this is a good practice can you at some point then delete the server redirects as google has marked them as permanent?
Technical SEO | | Breemcc0 -
Unsolved Why is Moz reporting 308s as 302s?
Got a looooong list of redirect issues in my crawl for a new client, all reported as 302s but as far as I can see they are all 308s... which is perfectly fine, right, or have I missed a memo? They even confirm the 308 status in the moz detail.
Moz Pro | | Algorhythm_jT0 -
Multilang site: Auto redirect 301 or 302?
We need to establish if 301 or 302 response code is to be used for our auto redirects based on Accept-Language header. https://domain.com
International SEO | | fJ66doneOIdDpj
30x > https://domain.com/en
30x > https://domain.com/ru
30x > https://domain.com/de The site architecture is set up with proper inline HREFLANG.
We have read different opinions about this, Ahrefs says 302 is the correct one:
https://ahrefs.com/blog/301-vs-302-redirects/
302 redirect:
"You want to redirect users to the right version of the site for them (based on location/language)." You could argue that the root redirect is never permanent as it varies based on user language settings (302)
On the other hand, the lang specific redirects are permanent per language: IF Accept-Language header = en
https://domain.com > 301 > https://domain.com/en
IF Accept-Language header = ru
https://domain.com > 301 > https://domain.com/ru So each of these is 'permanent'. So which is the correct?0 -
301 Redirect Timing Questions
Hey all, Quick question on 301 redirects and the timing of creating them when transitioning from an old site to a new site. Does the timing matter? Can redirects interfere with DNS propigation (which seemed to happen to us when we did redirects minutes after redirecting someone's DNS A record to now point to the new site) And lastly, how long AFTER a new site launch can one still submit redirects and not lose the google juice? All the best,
Technical SEO | | WorldWideWebLabs0 -
Redirect effecting ranking?
I manage the SEO for several different regions which are also based on the same site e.g. example.com/au, example.com/us The /us site has pretty good rankings and changes I'm making to the site are having an impact. The /au site has really bad rankings, even though much of the content is the same. (The /uk site is also awful but we had an issue with 4,500 duplicate pages which were only resolved last week). Crawl diagnostics are only showing 1 major error for a 404 response, I'm receiving a domain authority of 43 and A grade page ranking for some of our targeted keywords. I could believe that this isn't necessarily going to get us a top 10 rating but I would have thought we would be in the top 50, especially for branded keywords. Could the lack of ranking be to do with how our domain redirects? If you go to example.com.au you are taken to the home page rather than being redirected to example.com/au. Once you head to an internal page the URL changes to example.com/au/page
Technical SEO | | ahyde0 -
301 redirect all 404 pages
Hi I would like to have a second opinion on this. I am working on an ecommerce website that they 301 redirect all 404 pages (including the URLs entered incorrectly) to the “All categories page”. Will this have any negative SEO impact?
Technical SEO | | iThinkMedia0 -
How does this rank? - a page that is 301 redirected
How does a 301ed page rank in google? In google I searched for" ikea.ca" which is set up as a 301 redirect to www.ikea.com/ca/en and was surprised to see the url --> www.ikea.ca actually ranking. IKEA Canada <cite>ikea.ca/</cite>IKEA Featuring Scandinavian modern style furniture and accessories. Include storage options, lighting, decor products, kitchen appliances and beds. Bedroom - Kitchen - Living Room - IKEA North York
Technical SEO | | Morris770