Actually, I donβt know if there are better ways. As for the components, you pretty much got this: protocol, domain, and port.
If you want the colon to pass, you can do the following:
redirect_to(request.protocol + request.domain + (request.port.nil? ? '' : ":#{request.port}"))
Just a scratch test that does the magic!
source share