diff --git a/frappe/utils/data.py b/frappe/utils/data.py index ae74996247..9276a24d0a 100644 --- a/frappe/utils/data.py +++ b/frappe/utils/data.py @@ -714,9 +714,10 @@ def get_url(uri=None, full_address=False): return uri if not host_name: - if hasattr(frappe.local, "request") and frappe.local.request and frappe.local.request.host: - protocol = 'https://' if 'https' == frappe.get_request_header('X-Forwarded-Proto', "") else 'http://' - host_name = protocol + frappe.local.request.host + request_host_name = get_host_name_from_request() + + if request_host_name: + host_name = request_host_name elif frappe.local.site: protocol = 'http://' @@ -753,6 +754,11 @@ def get_url(uri=None, full_address=False): return url +def get_host_name_from_request(): + if hasattr(frappe.local, "request") and frappe.local.request and frappe.local.request.host: + protocol = 'https://' if 'https' == frappe.get_request_header('X-Forwarded-Proto', "") else 'http://' + return protocol + frappe.local.request.host + def url_contains_port(url): parts = url.split(':') return len(parts) > 2 diff --git a/frappe/www/sitemap.py b/frappe/www/sitemap.py index df51815329..8b93270ab5 100644 --- a/frappe/www/sitemap.py +++ b/frappe/www/sitemap.py @@ -15,7 +15,12 @@ base_template_path = "templates/www/sitemap.xml" def get_context(context): """generate the sitemap XML""" - host = get_request_site_address() + + # the site might be accessible from multiple host_names + # for e.g gadgets.erpnext.com and gadgetsinternational.com + # so it should be picked from the request + host = frappe.utils.get_host_name_from_request() + links = [] for route, page in iteritems(get_pages()): if page.sitemap: