4

I am trying to redirect to google.com using Magento.

Mage::app()->getResponse()->setRedirect('http://google.co.in'));

But when I use this code I am not able to open my home page too. It shows blank page.

What other code I can use instead of this so I can redirect to google.com?

Manoj Suryawanshi
  • 862
  • 1
  • 9
  • 20

2 Answers2

1

This should do the trick:

Mage::app()->getFrontController()->getResponse()->setRedirect('http://google.com');

Also, in your example you end with a double ), that might be the problem in your code.

Ossie7
  • 360
  • 3
  • 8
  • Actually I am using B2B extension and I am doing changes in Observer.php file also you can see my question here as I am having a problem in redirecting url "http://stackoverflow.com/questions/12494228/mydomain-error-in-magento-module" – Manoj Suryawanshi Sep 21 '12 at 09:04
  • In that question you made the same mistake, are you sure it's not just a double ending parentheses that is causing trouble? – Ossie7 Sep 21 '12 at 09:11
  • ok thanks. It was problem of double ending parentheses. But it is working on local machine only. But not on client server as mentions in problem in above link – Manoj Suryawanshi Sep 21 '12 at 09:26
  • To what address is your browser redirecting instead of google? – Ossie7 Sep 21 '12 at 09:27
  • its giving me error : 404 not found mydomain.com/errors/report.php?id=672761817356&skin=default (port 80) – Manoj Suryawanshi Sep 21 '12 at 09:37
  • Did you clear your cache? If that didn't help, what does your log say? var/log/exception.log and var/log/system.log of your server that gives 404 – Ossie7 Sep 21 '12 at 09:53
  • There is no file var/log/exception.log. In var/log/system.log 2012-09-19T10:00:00+00:00 ERR (3): Recoverable Error: Argument 1 passed to Mage_Core_Model_Store::setWebsite() must be an instance of Mage_Core_Model_Website, null gi$ 2012-09-19T10:00:00+00:00 ERR (3): Recoverable Error: Argument 1 passed to Mage_Core_Model_Store_Group::setWebsite() must be an instance of Mage_Core_Model_Website, n$ – Manoj Suryawanshi Sep 21 '12 at 10:03
  • Can you paste the last few lines on a pastebin or something? And did you clear magento's cache? – Ossie7 Sep 21 '12 at 10:50
  • 2012-09-19T10:00:00+00:00 ERR (3): Recoverable Error: Argument 1 passed to Mage_Core_Model_Store::setWebsite() must be an instance of Mage_Core_Model_Website, null gi$ 2012-09-19T10:00:00+00:00 ERR (3): Recoverable Error: Argument 1 passed to Mage_Core_Model_Store_Group::setWebsite() must be an instance of Mage_Core_Model_Website, n$ I had cleared magento's cache too. – Manoj Suryawanshi Sep 21 '12 at 11:15
0

try

Mage::app()->getResponse()->setRedirect($url)->sendHeaders()->sendResponse();
exit();

srgb
  • 4,783
  • 6
  • 29
  • 45
  • Its working fine on local, but my problem is its not working on client's server. See my question on http://stackoverflow.com/questions/12494228/mydomain-error-in-magento-module – Manoj Suryawanshi Sep 21 '12 at 10:20