diff --git a/lib/discourse.rb b/lib/discourse.rb index 456856b77c0..c787ffb9cbb 100644 --- a/lib/discourse.rb +++ b/lib/discourse.rb @@ -20,7 +20,11 @@ module Discourse # Get the current base URL for the current site def self.current_hostname - RailsMultisite::ConnectionManagement.current_hostname + if SiteSetting.force_hostname.present? + SiteSetting.force_hostname + else + RailsMultisite::ConnectionManagement.current_hostname + end end def self.base_uri default_value="" @@ -32,14 +36,19 @@ module Discourse end def self.base_url_no_prefix + default_port = 80 protocol = "http" - protocol = "https" if SiteSetting.use_ssl? - if SiteSetting.force_hostname.present? - result = "#{protocol}://#{SiteSetting.force_hostname}" - else - result = "#{protocol}://#{current_hostname}" + + if SiteSetting.use_ssl? + protocol = "https" + default_port = 443 end - result << ":#{SiteSetting.port}" if SiteSetting.port.present? && SiteSetting.port.to_i > 0 + + result = "#{protocol}://#{current_hostname}" + + port = SiteSetting.port.present? && SiteSetting.port.to_i > 0 ? SiteSetting.port.to_i : default_port + + result << ":#{SiteSetting.port}" if port != default_port result end