0

We run symfony v4.4.3, symfony-cmf 2.1.1 and symfony-cmf/routing-bundle 2.0.0.

We are using the cmf routing to load routes from db.

Symfony 4 should redirect from url with trailing slash to the same url without trailing slash, but it does not happen, trailing slash throws 404.

I started study the code what is happening where and why and I found in generated container router service getter, where is something like this

new DynamicRouter(
    new NestedMatcher(
        new UrlMatcher()
    )
)

UrlMatcher does not redirect if it is not instance of RedirectUrlMatcherInterface, but this base one is not.

So I realized it should be possible to inject RedirectableUrlMatcher to NestedRouter and I tried to find the way how to do it in documentation, but it was unsuccessful. So I took a look into cmf bundle routing extension, but I cant find any possibility to set specified router, or enable redirect.

But then I noticed RedirectableUrlMatcher is deprecated...

How to remove trailing slashes?

yivi
  • 42,438
  • 18
  • 116
  • 138
Huholoman
  • 76
  • 5
  • 1
    Did you try this one out: https://symfony.com/doc/4.0/routing/redirect_trailing_slash.html – Milos K Feb 06 '20 at 09:56
  • Yes, that actually works. The problem probably is that we have 2 routers, static and dynamic one. The redirect is in static router and it also applies to routes from dynamic router.. It works when I change priorities and make the dynamic router to be matched first. But I would prefer to have matched first the static one since its routes are used more often. – Huholoman Feb 07 '20 at 09:52

0 Answers0