Best Practice for 301 Redirect on www to non-www

We use as our main url. Google Analytics is complaining about: Property is receiving data from redundant hostnames. Some of the redundant hostnames are: and

Redundant hostnames are counted as separate rows in reports, so hits that are going to the same page on your site from different hostnames will be split into multiple rows. With data split across multiple rows, traffic to specific pages will appear lower than it actually is.

To avoid this problem, consider setting up a 301 redirect from one of your redundant hostnames to the other, or create a search-and-replace filter that strips “www.” from hostnames.

Is there a best practice via the hosts file?

Thank you in advance

In my case I researched further and use this solution:

Specifically:* Forwarding to$1 as a page rule

This is working perfectly now