Magento: Redirect functions
原文:http://blog.chapagain.com.np/magento-redirect-functions/
The redirect functions are present in Mage_Core_Controller_Varien_Action class.
/* Redirect to certain url */
_redirectUrl($url)
/* Redirect to certain path */
_redirect($path, $arguments=array())
/* Redirect to success page */
_redirectSuccess($defaultUrl)
/* Redirect to error page */
_redirectError($defaultUrl)
/* Set referer url for redirect in response */
_redirectReferer($defaultUrl=null)
/* Identify referer url via all accepted methods (HTTP_REFERER, regular or base64-encoded request param) */
_getRefererUrl()
/* Check url to be used as internal */
_isUrlInternal($url)
Example:
You can use the redirect functions in your controller class. Like below:-
$this->_redirect($path, $arguments=array());
// OR,
$this->_redirectUrl($url);
1
2
3
$this->_redirect($path, $arguments=array());
// OR,
$this->_redirectUrl($url);
The other way is:-
For redirect URL:-
$url = "http://example.com";
Mage::app()->getFrontController()->getResponse()->setRedirect($url);
1
2
$url = "http://example.com";
Mage::app()->getFrontController()->getResponse()->setRedirect($url);
For redirect with path and arguments:-
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl($path, $arguments));
1
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl($path, $arguments));
Hope it helps. Thanks.
原文:http://blog.csdn.net/yy20071313/article/details/43852879
$this->getResponse()->setHeader('HTTP/1.1','404 Not Found');
$this->getResponse()->setHeader('Status','404 File not found');
$this->_forward('defaultNoRoute');
#magento# 之 redirectuRL
http://blog.sina.com.cn/s/blog_6ea2cfe40101e1er.html
1.
protected function _redirect($path, $arguments = array())
{
return $this->setRedirectWithCookieCheck($path, $arguments);
}
2.
protected function _redirectError($defaultUrl)
{
$errorUrl = $this->getRequest()->getParam(self::PARAM_NAME_ERROR_URL);
if (empty($errorUrl)) {
$errorUrl = $defaultUrl;
}
if (!$this->_isUrlInternal($errorUrl)) {
$errorUrl = Mage::app()->getStore()->getBaseUrl();
}
$this->getResponse()->setRedirect($errorUrl);
return $this;
}
3.
protected function _redirectReferer($defaultUrl=null)
{
$refererUrl = $this->_getRefererUrl();
if (empty($refererUrl)) {
$refererUrl = empty($defaultUrl) ? Mage::getBaseUrl() : $defaultUrl;
}
$this->getResponse()->setRedirect($refererUrl);
return $this;
}
4.
protected function _redirectSuccess($defaultUrl)
{
$successUrl = $this->getRequest()->getParam(self::PARAM_NAME_SUCCESS_URL);
if (empty($successUrl)) {
$successUrl = $defaultUrl;
}
if (!$this->_isUrlInternal($successUrl)) {
$successUrl = Mage::app()->getStore()->getBaseUrl();
}
$this->getResponse()->setRedirect($successUrl);
return $this;
}
5.
protected function _redirectUrl($url)
{
$this->getResponse()->setRedirect($url);
return $this;
}
6.
protected function _rewrite()
7.
protected function _getRefererUrl()
{
8.
protected function _forward($action, $controller = null, $module = null, array $params = null)
{
#############example################
Mage::app()->getFrontController()->getResponse()->setRedirect('http://www.google.com');