cakePHP redirection with $this->referer() not working properly

cakephp, php

Solution

Try this

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

This will use FULL urls in your redirect and this may fix your problem with adding your redirect to the current URL instead of just using it.

Problem

I have one view file of TestController And on that I have added comment form (the url of page on which my page exist is www.example.com/test/view/slug)now comment form is posting on url www.example.com/comments/add action comment is adding successfully after addition I have written (in comment/add method) ``` $this->redirect($this->referer()); ``` what I was expecting is it should redirect to www.example.com/test/view/slug . its redirecting on that url on my localhost but when I deployed my application it is redirecting not redirecting propery it is redirecting on url www.example.com/comment/www.example.com and giving error ``` Error: The requested address '/comments/www.example.com' was not found on this server. ```

Original source