How to automatically redirect to the homepage based on browser language?

Hello, I have a multi-language site. default language is English. The alternative language is French.
I want to know how to automatically redirect to the homepage based on browser language.

ex, my browser is French, when I visit http://example.com/, I’ll be redirect to http://example.com/fr/.

If the browser language is English, go to http://example.com/.

You can enable language detection:

return [
  'languages.detect' => true
];

thx, I added it, but he did not redirect to the corresponding language url.
But I just tested it in a different language browser at localhost.

Have you cleared the browser cache or tried with a fresh browser? Have you made sure to only have a single return statement in your config?

I recreated the site and it works now. let me find out the difference.
thanks again @texnixe.