I don't want to add a new cgi variable called HOST because HOST sounds so generic and it might interfere with something else running in our environment. Or, I don't want to change the plsql cgi environment variable (such as HTTP_HOST) because many developers may use owa_util.get_cgi_env('HTTP_HOST') to get the current server. If the SERVER_PORT is part of the #HOST# then what could I change it to if it needs to be null. If you leave it blank, then the default SERVER_PORT comes from the CGI variables.The value of HTTP_HOST is wrong anyway and points to your internal web server, but I assume your developers actually want to get the host name of your external web server if they use it to generate absolute URLs. That's why I wouldn't bother and set it to the correct host name.
if l_protocol = 'https' thenWhich will remove the port :443 if you are using HTTPS and :80 if you are using HTTP from the final URL, because these are the defaults for those protocols anyway.
l_host_url := replace(l_host_url,':443/','/');
l_host_url := replace(l_host_url,':80/','/');