How to change Route respond To A specific Path?

To increase site loading time and decrease the pressure on my website I have decided to host files(js,css,images) in other hosting, like google storage or amazon aws, problem is that I already published a lot of posts that includes images other files in the html, like:

img src=site.example/wp-content/uploads/images/image.png

i can't go all over the posts to change the src attribute, so I want to change my route code so every time a wp-content or wp-includes files is requested, it will redirect it to the host where my media files are, something like:

    if(str_contains($path, 'wp-content') || str_contains($path, 'wp-includes')){
      redirect(host.example.$path);
    }

Topic uploads media redirect cdn Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.