开发者

How to redirect to non-zend link from zend application

My application is mixture of simple PHP webpages and zen开发者_StackOverflow中文版d 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


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');
    }
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜