3
votes

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.
1
check your routes.php there may be some problem . - Abhishek
I have written only one route in route.php which is used for home page redirection Router::connect('/', array('controller' => 'users', 'action' => 'home', 'home')); @Abhishek:is there is any problem then it should not work on my local as well. - Ganesh Patil
yes you are right, But there may be possibilities check your .htaccess files on local system as well as on your live server, Have you checked that a what value $this->referer() is giving it. - Abhishek
on both htaccess we have written only one rule RewriteRule (.*) app/webroot/$1 [L] . - Ganesh Patil
and url-rewriting tags in .htaccess are where as rewrite engine On ? and what is the value of this $this->referer() ? - Abhishek

1 Answers

13
votes

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.