I want to know what is the best way to implement what want (see below) in Silex.
Here is what I want:
- all URLs must start with locale (/en/page1, /fr/page1, /en/page2, /fr/page2, ….)
- when the user hits the home page I will check the browser language and add /en or /fr to home page
- when adding /en or /fr to home page, is there a way to do that in Silex without redirecting (I think redirecting home page is not a good SEO practice (my knowledge in SEO is very limited so maybe i am wrong))?
Thank you
2
Answers
You can have a look at http://silex.sensiolabs.org/doc/organizing_controllers.html
Especially :
So using this I think you can do something like :
I haven’t tried it but I think it would work, please let me know 🙂
To me, this was the simplest and cleanest option for Silex v2.x:
Install the silex-local package
composer require pmaxs/silex-locale "^2.0"
Add the LocalServiceProvidet to your app.php file:
This way, you won’t have to add anything extra in your endpoints, plus everything is handled by default.
Look at https://github.com/pmaxs/silex-locale for information with Silex v1.x.