JMSI18nRoutingBundle icon indicating copy to clipboard operation
JMSI18nRoutingBundle copied to clipboard

Redirect to no-prefix when the default locale prefix is manually added with prefix_except_default

Open mlpo opened this issue 10 years ago • 5 comments

Hello,

I encountered an issue and I did not find clean solutions, I want when I go to a page with the prefix of the default locale, I am redirected to the page without a prefix (which displays course the page in the default language).

For the moment with prefix_except_default :

  • http://example.com/fr/hello display the page in French
  • http://example.com/it/hello display the page in Italian
  • http://example.com/hello display the page in English (English is my default locale)
  • http://example.com/en/hello return 404 error

What I want :

  • http://example.com/fr/hello display the page in French
  • http://example.com/it/hello display the page in Italian
  • http://example.com/hello display the page in English (English is my default locale)
  • http://example.com/en/hello return to http://example.com/hello

Do you have any ideas?

Thanks

mlpo avatar Feb 28 '14 19:02 mlpo

What does http://example.com/en/ do? 404 error or a redirect to http://example.com/?

The former would mean you need a listener (sorta the reverse of the LocaleChoosingListener for the prefix strategy). The listener would have to check if the path is prefixed with a locale and if that locale is the default. If so, it should strip out the default locale and redirect.

The latter would mean an existing listener should be updated. But as far as I know, this listener does not exist yet.

Brammm avatar Mar 05 '14 10:03 Brammm

http://example.com/en/ return 404 error…

The idea of a listener is good, if you can reach a page with the variable by default (/en/hello) it redirects to the same address but without the local (/hello).

mlpo avatar Mar 05 '14 17:03 mlpo

I have same problem. How can solve this ?

sintanial avatar Mar 06 '14 07:03 sintanial

Well, as I said: create a listener. Have a look at the LocaleChoosingListener, create a similar one that will check if the first bit of the path is the default locale, if so, redirect...

Brammm avatar Mar 06 '14 08:03 Brammm

You could also solve this in your web server configuration.

patrick-mcdougle avatar Aug 16 '15 20:08 patrick-mcdougle