We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How to do a redirect on a url with a fragment?

Hi. How to do a redirect on a url with a fragment? example 'https://test.com/main#test'

return $this->response->redirect(array('for' => 'main'));

I'd try this:

function someAction() {
    $this-response->redirect($this->url->get(['for'=>'main']).'#test');
    return;
}


12.4k

Yes I can. But I guess it's not right?!

I'd try this:

function someAction() {
  $this-response->redirect($this->url->get(['for'=>'main']).'#test');
  return;
}

Why not right ? I guess phalcon is not supporting location hash fragment.



1.6k

You need the second parameter for this:

return $this->response->redirect($this->url->get(array('for' => 'main')) . '#test', true);

I've done this in Phalcon 2.0.10



12.4k

Many thanks to all for the reply. I understood that phalcon does not support fragment, so I'll use the above code.