mys Flarum will only work from the URL defined in config.php
(the one used during installation). It doesn't support being accessed via multiple URL. But it doesn't perform redirects automatically.
You should create redirects to the canonical domain in your webserver configuration. You can find examples for apache/nginx/other easily online, search "redirect www apache" or similar.
If you cannot or don't want to use webserver redirects, you can also use this Flarum extension https://discuss.flarum.org/d/19307-canonical-url-redirect