Effectively rewrite URL in WKWebView due to poor page implementation

I have a web app that I want to create an app for. This web app returns URLs with hardcoded IP addresses in the URLs as "http://ip-addr/path/to/link". I need to rewrite the URLs to just be "/path/to/link" as they should of been coded. How can I either respond to URL usage with a rewritten URL, or will I have to see the page loaded, and then scan the document and rewrite it?

Code examples would be great.

Currently, I see the following error when I click on one of these broken links: 2022-09-28 22:11:46.716274-0500 MyApp[64870:4826597] [Process] 0x7fef18012020 - [pageProxyID=6, webPageID=7, PID=64876] WebPageProxy::didFailProvisionalLoadForFrame: frameID=3, domain=NSURLErrorDomain, code=-1004, isMainFrame=1

I can't find a delegate method that is actually being called, so I really don't know how to at least see the load fail and try and get the URL, edit it, and then call the WKWebView to load the edited URL.

The primary issue is that this web page can be accessed from an external location and the address in the URL works for that external environment. But, on the local network, where the IP address is different, it also needs to work, and thus the need for the rewrite.

Effectively rewrite URL in WKWebView due to poor page implementation
 
 
Q