JMSI18nRoutingBundle icon indicating copy to clipboard operation
JMSI18nRoutingBundle copied to clipboard

Routing not working for /{slug} routes

Open picks44 opened this issue 8 years ago • 4 comments

Hello,

I have one route which is configured like this @Route("/{slug}", name="index_pages", requirements={"slug"=".+"})

I'm using Jmsi18nRouting with the prefix_except_default strategy and it's working fine everywhere, except for this routing : in the default (english) locale, the page is found (when the {slug} is contact for instance, like mysite.com/contact).

But on other languages, I have a 404 errors, page not found, because the {slug} is sent as locale/contact (I can't find the right page with this slug obiously), like mysite.com/sv_SE/contact.

What can I do to "bypass" the locale ?

picks44 avatar Feb 04 '16 17:02 picks44

Up ?

picks44 avatar Feb 08 '16 07:02 picks44

Same issue here. Do you have any clue ?

The issue seems to be from route priority :

  en__RG__catch_all ANY      ANY      www.site.fr     /{catchall}
  fr__RG__catch_all ANY      ANY      www.site.fr     /fr/{catchall}

I exclude /fr/ from beeing catched, so the second route can intercepte with the correct locale.

# Catch All
catch_all:
    path:     /{catchall}
    defaults:
        _controller: MyFrontBundle:Default:catchAll
    requirements:
        catchall: "^(?!fr/).+$"

My config.yml :

jms_i18n_routing:
    default_locale: %locale%
    locales:
        - en
        - fr
    strategy: prefix_except_default

p-bizouard avatar Apr 12 '16 07:04 p-bizouard

I recommend putting the default locale as the last item to the jms_i18n_routing.locales. This changes the order of the generated routes. (Remember to clear the cache even if you are in dev env.) E.g:

jms_i18n_routing:
    default_locale: en
    locales: [tr, en]
    strategy: prefix_except_default

taylankasap avatar Aug 03 '16 13:08 taylankasap

its been a long time, but i encountered this same problem and i can confirm what @taylankasap said is working. Just put the default locale at the end.

thanks !

zoomtronic avatar Jan 12 '22 12:01 zoomtronic