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

removeExtraSlashes not removing the ending slash from URL

i have this code in my routes.php file (app/config/routes.php)

<?php

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

$router->add('/contact-us', array(
    'controller' => "contact",
    'action' => "index"
));

$router->removeExtraSlashes(true);

return $router;

However, if I type

https://localhost/myproject/contact-us/

into the browser

the url will remain the same and the last slash is not removed.

I want this

https://localhost/myproject/contact-us

How to do that? Why is $router->removeExtraSlashes(true); not working as it was supposed to?

The worst part is that The user can type something like that: https://localhost/myproject/contact-us/////// and the slashes won't be removed ;(



37.0k

That's weird. It's not working for me. The routes and caching of them is so weird on my WAMP machine (windows). Could it be that?

Hi @Phalcon, @Flanex I have the same problem with removing extra slash. Currently I use PHP 5.5.13, Phalcon 1.3.2, Windows 7 SP1 64 bit. I guess that there are some problems with Windows binary distribution and it works only on Linux.



98.9k

Just to clarify, not sure if there is a misunderstanding here, this actually does not remove the slashes from the URL (what the user sees on the url bar in the browser), this removes the slashes from the uri handled by the router.

https://localhost/myproject/contact-us// is handled as https://localhost/myproject/contact-us but the URL is the same in the browser.



37.0k
edited Jul '14

Ok, so how to remove the trailing slashes in browser url bar in Phalcon then, if removeExtraSlashes is not for that purpose?



13.8k

Great question! I have the same "issue"

Ok, so how to remove the trailing slashes in browser url bar in Phalcon then, if removeExtraSlashes is not for that purpose?