schmittjoh / JMSI18nRoutingBundle

Allows you to internationalize your routing
http://jmsyst.com/bundles/JMSI18nRoutingBundle
358 stars 159 forks source link

Routing not working for /{slug} routes #181

Open picks44 opened 8 years ago

picks44 commented 8 years ago

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 commented 8 years ago

Up ?

p-bizouard commented 8 years ago

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
taylankasap commented 8 years ago

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
zoomtronic commented 2 years ago

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 !