Flarum doesn't redirect to the canonical URL automatically, but only the canonical URL will work.
You should configure the redirects manually in your Apache/nginx configuration. You should be able to find help for your specific situation by searching the web for "<webserver> <hosting company> www (or no-www) redirect". If you are on a managed hosting there might be a setting in your dashboard or a help page in their documentation to explain how to do it.
You can also use this extension to have Flarum do the redirects for you, but it's a bit less performant https://discuss.flarum.org/d/19307-canonical-url-redirect