This will have the following problems:

1) It will not find links with the https protocol.
2) It will change all links, regardless of whether they are internal or external. Only internal links should be replaced. An approach for that could be to require the Setting.host_name value to be included.
3) It will not find links to openproject instances that have a document root other than "/" defined (e.g. https://www.openproject.org/beta/issues/584)
4) It will not find links where the hostname includes a ".".