URL rewrite to other domain for all local requests

Is it possible to rewrite all URL’s (routes) inside a rails app for
all local request to link to other domain if RAILS_ENV=test.

If I open the application at www.domain_for_private_site.com, then all
forms, links, etc, should make requests on

For example, if I make a get request on
that contains something like:

and it should be changed with this:

same for all other URL’s.

It should be done in Rails, not in Apache server or similar.