request('HEAD', $url, [ 'on_stats' => function( GuzzleHttp\TransferStats $stats ) use ( &$effectiveURL ){ $effectiveURL = $stats->getEffectiveUri(); }]) ->getBody()->getContents(); } catch(\Exception $e) { error_log($e); return $url; } return $effectiveURL->__toString(); } function getURL() { if ( empty($_REQUEST['url']) ) { $data = json_decode(file_get_contents('php://input'), true); return $data['url']; } else { return $_REQUEST['url']; } } function resolve() { return json_encode( ['url' => resolveURL( getURL() ) ]); }