Details
-
Type:
Improvement
-
Status:
Resolved
-
Priority:
Trivial
-
Resolution: Fixed
-
Affects Version/s: 1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.5.0RC1, Next Major Release
-
Fix Version/s: 1.5.0
-
Component/s: Zend_Controller
-
Labels:None
-
Fix Version Priority:Should Have
Description
There is a problem with Zend_Controller_Action::_redirect(), which proxies to Zend_Controller_Action_Helper_Redirector::gotoUrl():
Sample:
Application URI: http://www.example.com
Application base path: either empty or /
Current URI: http://www.example.com/foo
Controller-Command:
$this->_redirect('bar');
Expected target URI:
http://www.example.com/bar
What currently happens:
http://www.example.com/foo/bar
However, if the application path is a subdirectory, everything works fine.
The problem is related to the code in the Zend_Controller_Action_Helper_Redirector::_prependBase() function:
/**
* Determine if the baseUrl should be prepended, and prepend if necessary
*
* @param string $url
* @return string
*/
protected function _prependBase($url)
{
if ($this->getPrependBase()) {
$request = $this->getRequest();
if ($request instanceof Zend_Controller_Request_Http) {
$base = rtrim($request->getBaseUrl(), '/');
if (!empty($base) && ('/' != $base)) {
$url = $base . '/' . ltrim($url, '/');
}
}
}
return $url;
}
The problem can easily be fixed by adding two lines:
/**
* Determine if the baseUrl should be prepended, and prepend if necessary
*
* @param string $url
* @return string
*/
protected function _prependBase($url)
{
if ($this->getPrependBase()) {
$request = $this->getRequest();
if ($request instanceof Zend_Controller_Request_Http) {
$base = rtrim($request->getBaseUrl(), '/');
if (!empty($base) && ('/' != $base)) {
$url = $base . '/' . ltrim($url, '/');
} else {
$url = '/' . ltrim($url, '/');
}
}
}
return $url;
}
Scheduling for 1.5.0RC2