You can filter site_url
using a filter – called site_url
The hook has the following signature:
apply_filters( 'site_url', string $url, string $path, string|null $scheme, int|null $blog_id )
You can use it like this:
add_filter( 'site_url', 'wpse_381006_custom_site_url', 10, 1 );
function wpse_381006_custom_site_url( $url ){
if( is_admin() ) // you probably don't want this in admin side
return $url;
// for example, return the request_uri - but this is not a complete solution, you would need to work out what you return and in what conditions..
return $_SERVER['REQUEST_URI'];
}
Reference: https://developer.wordpress.org/reference/hooks/site_url/