Redirecting to external or internal URL from within a Magento controller

Submitted by deeperdata - 1 year ago

While developing an extension, I came across the need to redirect the user away from the admin panel to an external URL/route . I learned that Magento had options for redirecting depending on whether or not the URL was based internally or externally. The issue I experienced is that my external URLs were prefixed with Magento's base URL. See the below code for both methods:

// To redirect to external URL and avoid having your base URL prepended to each link:

<?php

$url = "http://www.magetricks.com/";
$this->_redirectUrl($url);

// To redirect to internal URL/route:

$path = "module/controller/action/param1/param1value";
$this->_redirectUrl($url);
affiliate_link
Learn PHP
comments powered by Disqus
Proudly hosted on Digital Ocean