How to redirect outgoing links via my own website

Here is a simple solution..

  1. Create a page that you want to use as your redirect handler and get the ID of that page.

  2. This goes into your theme’s functions.php or any of your plugin file.

    function wpse405640_redirect() {
         if ( is_page(123) ) { //Assuming your page id is 123
             $redirect = isset($_GET['url']) && !empty($_GET['url']) ? $_GET['url'] : home_url("https://wordpress.stackexchange.com/");
             wp_redirect( $redirect );
             exit;
         }
     }
     add_action('template_redirect', 'wpse405640_redirect');

The URL structure should be https://myownsite.com/redirect/?url=https://recipes.com/applepie.