CakePHP redirect with $ this-> referer () doesn't work as expected

I have one TestController view file. And on that, I added a comment form (the url of the page my page is on is www.example.com/test/view/slug). The comment form is posted on the url www. example.com/comments/add an action comment is successfully added after the add I wrote (in the comment / add method)

            $this->redirect($this->referer());

      

I expected it to redirect to www.example.com/test/view/slug. it redirects to this url on my localhost, but when i deployed my app it does not redirect redirect, it redirects to www.example.com/comment/www.example.com url and gives error

Error: The requested address '/comments/www.example.com' was not found on this server.

      

+2


source to share


1 answer


try it

$this->redirect( Router::url( $this->referer(), true ) );



Your redirect will use FULL URLs and this might fix your problem of adding the redirect to the current URL rather than just using it.

+9


source







All Articles