# Trailing slash on end url

**URL:** <https://discourse.cakephp.org/t/trailing-slash-on-end-url/6961>\
**Category:** Need Help\
**Created:** [December 7, 2019, 7:45pm UTC](https://discourse.cakephp.org/t/trailing-slash-on-end-url/6961 "2019-12-07T19:45:44Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![shadowx.jb](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@shadowx.jb](https://discourse.cakephp.org/u/shadowx.jb)\
**Post date:** [December 7, 2019, 7:45pm UTC](https://discourse.cakephp.org/t/trailing-slash-on-end-url/6961/1 "2019-12-07T19:45:44Z")

</div>

In the router I have set the URL as follows.

> $routes-\>connect(‘/page-test/’, [‘controller’ =\> ‘Test’, ‘action’ =\> ‘display’]);

If I call a url without a slash at the end, the URL works as well. I need to disable this rule so that URLs work only with a slash at the end, as defined in the router. In debug mode, the routing tab - you can see that all rules are without a slash at the end. Please, give me an advice.

---

<div class="post-metadata">

**Author:** ![jimgwhit](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/jimgwhit/32/378_2.png) [@jimgwhit](https://discourse.cakephp.org/u/jimgwhit)\
**Post date:** [December 7, 2019, 10:27pm UTC](https://discourse.cakephp.org/t/trailing-slash-on-end-url/6961/2 "2019-12-07T22:27:57Z")

</div>

I have routes like this:

```auto
$routes->connect('/dog/index', ['controller' => 'Dogs', 'action' => 'index']);

```

And no problems. Clear any cache after making changes.

I forget if cake caches routes, if so clear that cache as well.

---

<div class="post-metadata">

**Author:** ![shadowx.jb](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@shadowx.jb](https://discourse.cakephp.org/u/shadowx.jb)\
**Post date:** [December 8, 2019, 7:13am UTC](https://discourse.cakephp.org/t/trailing-slash-on-end-url/6961/3 "2019-12-08T07:13:24Z")

</div>

As I wrote, I need a slash at the end. If I clear the cache, the problem is the same, routing variables are still without a slash at the end. Is it possible to set what I have written in the router so that it respects the rules?

May not work: /page-test  
Must work: /page-test/

---

<div class="post-metadata">

**Author:** ![jimgwhit](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/jimgwhit/32/378_2.png) [@jimgwhit](https://discourse.cakephp.org/u/jimgwhit)\
**Post date:** [December 10, 2019, 12:36am UTC](https://discourse.cakephp.org/t/trailing-slash-on-end-url/6961/4 "2019-12-10T00:36:04Z")

</div>

First, if your route has parameters, the docs explain how to use parameters:  
[https://book.cakephp.org/4/en/development/routing.html#passing-parameters-to-action](https://book.cakephp.org/4/en/development/routing.html#passing-parameters-to-action)

The example I gave has no parameters, so why would you need an extra slash.

Example just a url (no) parameters [https://cakephp.org](https://cakephp.org)

With parameters [https://book.cakephp.org/3/en/development/configuration.html](https://book.cakephp.org/3/en/development/configuration.html)

---

<div class="post-metadata">

**Author:** ![shadowx.jb](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@shadowx.jb](https://discourse.cakephp.org/u/shadowx.jb)\
**Post date:** [December 10, 2019, 5:46am UTC](https://discourse.cakephp.org/t/trailing-slash-on-end-url/6961/5 "2019-12-10T05:46:57Z")

</div>

I need all URLs to end with a slash. Is there any way to do it?

---

<div class="post-metadata">

**Author:** ![Salines](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/salines/32/3166_2.png) [@Salines](https://discourse.cakephp.org/u/Salines)\
**Post date:** [December 10, 2019, 12:58pm UTC](https://discourse.cakephp.org/t/trailing-slash-on-end-url/6961/6 "2019-12-10T12:58:47Z")

</div>

Take look: [https://stackoverflow.com/questions/11829714/add-trailing-slash-htaccess](https://stackoverflow.com/questions/11829714/add-trailing-slash-htaccess)

---

<div class="post-metadata">

**Author:** ![shadowx.jb](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@shadowx.jb](https://discourse.cakephp.org/u/shadowx.jb)\
**Post date:** [December 10, 2019, 1:05pm UTC](https://discourse.cakephp.org/t/trailing-slash-on-end-url/6961/7 "2019-12-10T13:05:43Z")

</div>

And a solution without 301 redirects?

---

<div class="post-metadata">

**Author:** ![jimgwhit](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/jimgwhit/32/378_2.png) [@jimgwhit](https://discourse.cakephp.org/u/jimgwhit)\
**Post date:** [December 11, 2019, 4:01am UTC](https://discourse.cakephp.org/t/trailing-slash-on-end-url/6961/8 "2019-12-11T04:01:22Z")

</div>

Have you tried stackoverflow for your redirect question.

---

<div class="post-metadata">

**Author:** ![shadowx.jb](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@shadowx.jb](https://discourse.cakephp.org/u/shadowx.jb)\
**Post date:** [December 11, 2019, 8:54am UTC](https://discourse.cakephp.org/t/trailing-slash-on-end-url/6961/9 "2019-12-11T08:54:43Z")

</div>

I haven’t tried because it is a 301 redirect. I need the router to work as I define it. The page /page-test/ works, but if I have a paginator, the links in it refer to /page-test?page=2, etc., how do I make a slash in the paginator? Without slashing my paging doesn’t work.

And why not see a slash in the debug router when I have it in my code?

```
	$routes->connect('/page-test/', ['prefix' => 'Pages', 'controller' => 'Test', 'action' => 'display']);
```
