diff --git a/src/ui/databrowserModule/kgSingleDatasetService.service.ts b/src/ui/databrowserModule/kgSingleDatasetService.service.ts
index 871f566b58d7f0cf90ac362aa3b6fa612f6d4ee6..f5abf717d1d08201c99bba3c63fa17c79fe89a28 100644
--- a/src/ui/databrowserModule/kgSingleDatasetService.service.ts
+++ b/src/ui/databrowserModule/kgSingleDatasetService.service.ts
@@ -57,7 +57,7 @@ export class KgSingleDatasetService implements OnDestroy {
   }
 
   public getDownloadZipFromKgHref({ kgSchema = 'minds/core/dataset/v1.0.0', kgId }) {
-    const _url = new URL(`datasets/downloadKgFiles`, BACKENDURL)
+    const _url = new URL(`${BACKENDURL.replace(/\/$/, '')}/datasets/downloadKgFiles`)
     const searchParam = _url.searchParams
     searchParam.set('kgSchema', kgSchema)
     searchParam.set('kgId', kgId)
diff --git a/src/util/constants.ts b/src/util/constants.ts
index 901f704818fc711f396f6dbce6a5b525e08e1a05..8945936fadfaececc1838f726d6b80a51473b8f2 100644
--- a/src/util/constants.ts
+++ b/src/util/constants.ts
@@ -14,7 +14,13 @@ export const LOCAL_STORAGE_CONST = {
 export const COOKIE_VERSION = '0.3.0'
 export const KG_TOS_VERSION = '0.3.0'
 export const DS_PREVIEW_URL = DATASET_PREVIEW_URL
-export const BACKENDURL = BACKEND_URL || 'http://localhost:3000/'
+export const BACKENDURL = BACKEND_URL && /^http/.test(BACKEND_URL)
+  ? BACKEND_URL
+  : (() => {
+    const url = new URL(window.location.href)
+    const { protocol, hostname, pathname } = url
+    return `${protocol}//${hostname}${pathname}`
+  })() || 'http://localhost:3000/'
 
 export const MIN_REQ_EXPLAINER = `
 - Interactive atlas viewer requires **webgl2.0**, and the \`EXT_color_buffer_float\` extension enabled.