Changed to use Kohana environment variable instead of a server environment variable that may not be defined.
Added logic to set a default sub_domain value of 'www' if no domain is present.