Question

My application is mixture of simple PHP webpages and zend application. Sometime I need to redirect to simple PHP webpage from zend application's Action.

For example:

I want to redirect from example.com/module/controller/action to example.com/simplephp.php.

I tried header("Location: example.com/simplephp.php"); but it is not working.

Thanks

Was it helpful?

Solution

Yes, the basic redirect action helper allows you to redirect to any URL.

class MyController extends Zend_Controller_Action {
    public function indexAction() {

        $this->_redirect('/path/to/any/page.php');
        // or
        $this->_redirect('http://example.com/anypage.php');
    }
}

OTHER TIPS

HTTP/1.1 requires an absolute URI as argument. Request should contain http:// or https://

You should manipulate the request object, which sends HTTP headers.

If you want to do:

header("Location: example.com/simplephp.php");

you need:

$request->setHeader('Location', 'example.com/simplephp.php', true);

Then you need to turn off the layout, view rendering and any other things which are not needed etc.

The easy way to handle the redirects without worrying too much about the details is the Redirector action helper. You may use it even outside the controller retrieving it's static instance from Helper Broker.

Note, that even if shortened URLs work in almost all of the browsers, you always should specify full URL for location (including protocol and domain name) as specified in HTTP 1.1.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top