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
-
Over Optimised Magento Pages
We are working on a clients Magento site and we've added new copy which has a decent keyword density which is in line with best practice. When we run it through Moz we are getting a Key Word Stuffing alert saying the page has 27 keywords, where we can only see about 11. This is the page https://www.greatbeanbags.com/bean-bag-cushions The client is pushing back saying the page must have already been optimised before as our new copy has triggered the stuffing alert. But my guess is the page was already stuffed but buy some Magento code we can't see. Any ideas? #magento #Keyworddensity
Content Development | | Marketing_Optimist0 -
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 -
Magento Category Suffix - redirect issue
Hi All, Just launched a new Magento store & set the category suffix to blank & not .html or / So the desired url is https://www.example.com/category-1 But I am seeing a 301 redirect being implemented: https://www.example.com/category-1/ redirect to: https://www.example.com/category-1 I cant see this is the list of 301 redirects within the redirect panel in Magento but Moz & another redirect checker is picking it up. I am missing a setting or something ? Many Thanks,
Technical SEO | | PaddyM556
Pat0 -
To avoid errors in our Moz crawl, we removed subdomains from our host. (First we tried 301 redirects, also listed as errors.) Now we have backlinks all over the web that are broken. How bad is this, from a pagerank standpoint?
Our MOZ crawl kept telling us we had duplicate page content even though our subdomains were redirected to our main site. (Pages from Wineracks.vigilantinc.com were 301 redirected to vigilantinc.com/wineracks.) Now, to solve that problem, we have removed the wineracks.vigilantinc.com subdomain. The error report is better, but now we have broken backlinks - thousands of them. Is this hurting us worse than the duplicate content problem?
Technical SEO | | KristyFord0 -
Enable cookies temporary redirect
We have a ton of warnings - over 10 k - that are paths that SEOMOZ is getting redirected to an enable cookies page - but anyone with cookies enabled is not. Does this matter?
Technical SEO | | JohnBerger0 -
404 page for webshop vs 302 redirect
Hi everybody Im the owner of a webshop and we have implemented that products that are not instock are disabled from the shop. My problem is that i have a lot of 404 pages, that right now get redirected to the front page, when the item are not instock. This is because it would hurt the conversion rate if they got a standard 404 page. Customers dont know what a 404 and would click back and choose another competitor. Its really hard to find out what are the best solution and what are not a downrank at google. This has been running like this for 2 years and cant see any negative in the solution regarding seo and so on, What are your thoughts? Christian Hansen Denmark
Technical SEO | | noerdar0 -
Multiple redirects a problem?
When product is sold out I will 301 redirect to a category page if a similar product is not available, but now our web developer has changed all the url's of the category pages so I need to redirect them all to the new category pages but that means there are some products that are first being redirected to the no longer existent category and then being redirected again to the new category page. This seems like it might me be a problem having two 301 redirects so I wanted to find out for sure if it is. Unfortunately our system for redirecting pages is archaic so it will be difficult and time consuming to go back and redo all the redirects that are going to pages that no longer exist so I wanted to get some additional opinions before I do that.
Technical SEO | | KentH0 -
Is a 302 useful here?
We have a site that had one super successful viral video a couple of years back and basically the site needs a ton of work to even be functional. We don't have the time or the resources to even touch it. Our video is still getting tons of views today and I'm fairly certain it's the only reason the site still gets traffic. Most of the views come from youtube which prompts them to check out the site. We plan on going back to the site at a later date, but for now wanted to redirect it to another site of ours. In this case is it best practice to 302? or is a 301 still the proper solution?
Technical SEO | | ClaytonKendall0