11
votes

I have an issue on a Magento site I'm working on with a 302 redirect. Something in the site/theme is causing a 302 redirect on the site.com/blog link to go to the homepage if I have the theme's default blog module disabled. I'm trying to get that url to use as the homepage of a WordPress install but this native module has hijacked it and I can't find where it's happening.

If the module is on, it's fine and uses the link but when you turn it off, it redirects. I'm guessing this is native to the module but for some reason I can't seem to change that behavior and disable it entirely (ideally it would be good if I got a 404 error when the blog module was off because at least I know that the URL is available for me to use).

With the module off, I've visited the page on Chrome and listened in on the Network tab of Developer Tools. A 302 redirect does appear.

HTTP/1.1 302 Moved Temporarily
Date: Sat, 08 Aug 2015 00:01:45 GMT
Server: Apache
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
X-Frame-Options: SAMEORIGIN
Set-Cookie: frontend=80cfd66318165451fa4aa2915d139404; expires=Sat, 08-Aug-2015 02:01:45 GMT; path=/; domain=www.example.com; httponly
Location: http://www.example.com/
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8

GET /blog HTTP/1.1
Host: www.example.com
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.125 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8
Cookie: _gaost=.rk=; _gaos=.gaos_r=(direct).mc=(no)|(no)|(no).gaos_k=.pc=2; __ar_v4=M5J3LQW4MFADRNVY2ORZM7%3A20150610%3A4%7CN3LC2IOELZFOVNMCXKXXWV%3A20150610%3A4%7C5DCLBJIK7FDQFMXMCEDBUU%3A20150610%3A4; frontend=80cfd66318165451fa4aa2915d139404; __utma=176154288.93372352.1432329461.1435683793.1435792914.29; __utmz=176154288.1432329461.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __atuvc=3%7C26%2C3%7C27%2C17%7C28; adminhtml=d90076dbca44dcccdd004d86240b9683; adminhtml=d90076dbca44dcccdd004d86240b9683; frontend=80cfd66318165451fa4aa2915d139404

I know that 302s can be caused by .htaccess files so I SSHed into the server and used find to locate all .htaccess files on the server (and found 17) but none of them had any redirect code that would affect that page.

Is there any way to detect where/why/how the 302 redirection is happening? There is no documentation on this issue for this module/plugin, I've looked everywhere and even contacted the developer but haven't heard back.

Thanks for your help.

2
302 redirects don't only happen because of .htaccess, search for header("Location: statements. Run a grep to see if you can find the evil-doer.Rimble
After doing what @Tom Kriek said, flush the cache before trying again.Valentin Montmirail
@TomKriek, great thought on that. I ran a grep and didn't find any header calls that are related to the blog. Are there other instances of 302 redirects that I'm not taking into account?MillerMedia

2 Answers

7
votes

I found out the issue.

This had to do with 'routing' in Magento. There is a function called addRoute and I did a grep on the server looking for 'addRoute' and found a bunch of files it was happening in.

I was able to then locate the folder where the whole blog module was doing the redirect and had to just go through the logic of module and disable some of the functions in it's class.

4
votes

Magento is a great platform with a huge number of options and capabilities but 302 redirects is something that takes place on almost every eCommerce/blog website.

There a lot of issues about 302 redirection in Magento.

Sometimes you set 301 redirect in System > Configuration > General > Web > Url Options but it keeps showing 302, sometimes you get alerts about a huge number of pages like example.com/blog/post/1234 with 302 redirection, etc.

Magento automatically sets 302 redirects for urls like:

  • Add to Compare
  • Add to wishlist
  • Switch currency
  • Switch location
  • ...

(Source: https://www.mavenecommerce.com/blog/302-redirects-in-magento/)

So try to go to System > Configuration > General > Web > Url Options to change (if possible) directly from the option of Magento. It's probably possible to change it directly from there.