To handle Canonical URL is it best practice to do a 301 redirect or better to have the same IP Address for both www and non www domain?
For example:
Canonical UR
You may try redirect.center. Its redirects domains using DNS only.
So it will fulfill your DNS configurations:
Domain | A Record
------------------------------------
example.com | 192.0.2.34
* www.example.com 301 redirect to example.com
set your DNS record to:
CNAME | www | example.com.opts-https.redirect.center
Note:
The .opts-https.
parameter redirect to https
domain
If you use only http
domain then use .opts-uri.