Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend _redirect error: prepends base url twice

I'm experiencing irregular behavior using the Zend controller _redirect method.

My copy of the application is yielded via a symlink in my DocumentRoot. Also my default router is customized to respond to this pattern:

http://localhost/<appSymLink>/<param_A>/<controller>/<action>/

From a controller, I construct a URL like so:

$url = $this->_helper->url('action', 'controller', $param_A = 'valueA');

If I access the url:

http://localhost/<appSymLink>/<param_A>/<controller>/<action>/

This variable contains the following string:

/<appSymLink>/<param_A>/<controller>/<action>/

And when I call

$this->_redirect($url);

The user is explicitly redirected to this path, with redundant base paths.

/<appSymLink>/<appSymLink>/<param_A>/<controller>/<action>/

Zend seems to be prepending the base path twice.

My co-worker's copy of the application lives in his DocumentRoot, and he is not experiencing this problem.

Defining an empty base path inside the action, just before the operation, works like so:

$this->getRequest()->setBaseUrl('');

This is not a feasible solution obviously. On the other hand, doing this within a controller plugin at routeShutdown eliminates both occurrences of the application directory.

Does anyone have advice for a solution to this problem, or any tips for looking fourther into it?

like image 753
Daniel B. Avatar asked Jan 25 '12 01:01

Daniel B.


2 Answers

If redirecting with a URL generated from the Url helper, you need to inform the redirector that it is already prefixed with the base URL.

Simply use the following

return $this->redirect($url, array('prependBase' => false));
like image 118
Phil Avatar answered Oct 23 '22 13:10

Phil


Try and set the prependBase option to FALSE:
$this->_redirect($url, array('prependBase' => FALSE);

Excerpt from ZF reference:

_redirect($url, array $options = array()): redirect to another location. This method takes a URL and an optional set of options. By default, it performs an HTTP 302 redirect.

The options may include one or more of the following:

exit: whether or not to exit immediately. If requested, it will cleanly close any open sessions and perform the redirect.

You may set this option globally within the controller using the setRedirectExit() accessor.

prependBase: whether or not to prepend the base URL registered with the request object to the URL provided.

You may set this option globally within the controller using the setRedirectPrependBase() accessor.

code: what HTTP code to utilize in the redirect. By default, an HTTP 302 is utilized; any code between 301 and 306 may be used.

You may set this option globally within the controller using the setRedirectCode() accessor.

if this dosen't work may I suggest the action helper 'Redirector' commonly used:
$this->_helper->getHelper('Redirector')->gotoSimple($action, $controller = null, $module = null, array $params = array())
Action Helper Redirector

like image 4
RockyFord Avatar answered Oct 23 '22 14:10

RockyFord