How I can make a redirect page?

I want to create a simeple page on my website that redirects users to another page based on url parameters in javascript. Basically I want to have something like this url https://example.com/go?redirect=google.com that when visited redirects users to google or any url entered in after ?redirect=.

I have got it working but I want to give it a bit of delay

<script>
var url = new URL(window.location.href);
    var navigate = url.searchParams.get("redirect");
    window.location.href=navigate;
</script>