We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Trailing Slashes in URL

I'm having a trouble regarding the trailing slashes when i used this code

$this->response->redirect( array( 'for' => 'admin', 'controller' => 'test' ));

and it gives me this "http://localhost/admin/test//" and what i want is "http://localhost/admin/test" and if I add this

$this->response->redirect( array( 'for' => 'admin', 'controller' => 'test', 'action' => 'index' ));

the result is this "http://localhost/admin/test/index/" , it should be like this "http://localhost/admin/test/index" .

My question is how can i remove the trailing slashes and how can I append ".html" as its extension?

"http://localhost/admin/test/index.html" or "http://localhost/admin/test.html"

I don't know for sure, but perhaps it is the routes you've set up?

$router = new \Phalcon\Mvc\Router();

//Remove trailing slashes automatically

To: Sum

I already tried that but it only applies if I'm getting the address using the url/request module of phalcon. What I want is to be remove from the address bar automatically when I used this code:

$this->response->redirect( array( 'for' => 'admin', 'controller' => 'test' ));

The result should be like this "http://localhost/admin/test/index.html".

To: quasipickle

I'm figuring out what do you mean in my routers set up..


hi, can provide your route. I confirm the problem exists when i add route with parameters and just redirect it without parameters. eg:

$router->add('/admin/{foo}/{bazz}', array(
    'controller' => 'user_control',
    'action' => 'moo'
// and just redirect without parameters
// u see i guess that is at least 1 paremeter (bazz)
$this->response->redirect( array( 'for' => 'admin'));
//yes it will give extra slashes because foo or bazz not filled

//but if the route is
$router->add('/admin, array(
    'controller' => 'user_control',
    'action' => 'moo'
//just work

Hi Sum tnx for your help, I already fix the problem in trailing slashes by this code

$router->add('/admin/:controller/:action/:params', array( 'controller' => 1, 'action' => 2 'param' => 3 ))->setName('admin-full');

$router->add('/admin/:controller/:action', array( 'controller' => 1, 'action' => 2 ))->setName('admin-action');

$router->add('/admin/:controller', array( 'controller' => 1, ))->setName('admin-controller');

The problem was I have set the name of the router the same to each other as "admin". So the redirect will get the first route with trailing slahes. The only thing now is how can i append extension to the url like .html or .json.


Hi, glad to know you solved the problem.

but i just think

$router->add('/admin/:controller/:action/:params', array( 'controller' => 1, 'action' => 2 'param' => 3 ))->setName('admin');

is enough