It looks like you are on the right track, but it doesn’t work right. When I go to https://www.example.com it redirects to https://www.example.com/welcome, but I get the following message in Firefox.
The page isn’t redirecting properly
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
To clarify what I did: I copied your code to the very top of index.php on the root of my website and changed the URL from example.com to my own URL.
Let me know if I am doing something wrong.