Prevent Google from indexing netlify URL

I created a _redirects file based on the solution described here. The file says:

https://example.netlify.app https://example.com 301!
http://example.netlify.app  https://example.com 301!

Do I also need to add the custom headers rule? According to this Google article: "If you need to change the URL of a page as it is shown in search engine results, we recommend that you use a server-side 301 redirect. "

Please clarify if the current setup is enough or if the _headers file is required too.

Thank you!