JMSI18nRoutingBundle
JMSI18nRoutingBundle copied to clipboard
Redirect to no-prefix when the default locale prefix is manually added with prefix_except_default
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 tohttp://example.com/hello
Do you have any ideas?
Thanks
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.
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).
I have same problem. How can solve this ?
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...
You could also solve this in your web server configuration.