diff --git a/layouts/partials/product-info.html b/layouts/partials/product-info.html
new file mode 100644
index 0000000000..f35a1ade44
--- /dev/null
+++ b/layouts/partials/product-info.html
@@ -0,0 +1,74 @@
+{{- /*
+ Returns a dict with product path information extracted from the page.
+
+ Uses .File.Dir when available (baseURL-independent) with fallback to .RelPermalink.
+ This ensures product detection works correctly regardless of baseURL configuration,
+ including PR preview deployments at subdirectory paths.
+
+ Usage:
+ {{ $productInfo := partial "product-info.html" . }}
+ {{ $productInfo.product }} - e.g., "influxdb3", "influxdb", "flux"
+ {{ $productInfo.version }} - e.g., "core", "enterprise", "v2", "cloud"
+ {{ $productInfo.isOSS }} - true if version matches ^v[0-9] (OSS versioned product)
+ {{ $productInfo.productKey }} - normalized key for product aliases
+ {{ $productInfo.productRef }} - key for .Site.Data.products lookup
+ {{ $productInfo.productData }} - product data from .Site.Data.products (may be nil)
+*/ -}}
+
+{{- /* Extract path from .File.Dir or fall back to .RelPermalink */ -}}
+{{- $path := "" -}}
+{{- if .File -}}
+ {{- /* .File.Dir returns the directory path relative to content/, e.g., "influxdb3/core/get-started/" */ -}}
+ {{- $path := .File.Dir -}}
+ {{- $.Scratch.Set "productPath" $path -}}
+{{- else -}}
+ {{- /* Fallback: strip site base path from RelPermalink */ -}}
+ {{- $.Scratch.Set "productPath" .RelPermalink -}}
+{{- end -}}
+{{- $path = $.Scratch.Get "productPath" -}}
+
+{{- /* Parse path segments - handles both File.Dir (no leading slash) and RelPermalink (leading slash) */ -}}
+{{- $pathSegments := findRE "[^/]+" $path -}}
+{{- $product := index $pathSegments 0 | default "" -}}
+{{- $version := index $pathSegments 1 | default "" -}}
+
+{{- /* Determine if this is an OSS version (matches v1, v2, etc.) */ -}}
+{{- $isOSS := ne (len (findRE `^v[0-9]` $version)) 0 -}}
+
+{{- /* Calculate product key - use "oss" for versioned products, otherwise use the version */ -}}
+{{- $productKey := cond $isOSS "oss" $version -}}
+
+{{- /* Product aliases map version/product keys to .Site.Data.products keys */ -}}
+{{- $productAliases := dict
+ "oss" "influxdb"
+ "cloud" "influxdb_cloud"
+ "cloud-tsm" "influxdb_cloud"
+ "core" "influxdb3_core"
+ "enterprise" "influxdb3_enterprise"
+ "cloud-serverless" "influxdb3_cloud_serverless"
+ "serverless" "influxdb3_cloud_serverless"
+ "cloud-dedicated" "influxdb3_cloud_dedicated"
+ "dedicated" "influxdb3_cloud_dedicated"
+ "clustered" "influxdb3_clustered"
+ "explorer" "influxdb3_explorer"
+-}}
+
+{{- /* Look up the product reference */ -}}
+{{- $productRef := index $productAliases $productKey -}}
+
+{{- /* Get product data (may be nil if productRef is not found) */ -}}
+{{- $productData := dict -}}
+{{- if $productRef -}}
+ {{- $productData = index .Site.Data.products $productRef | default dict -}}
+{{- end -}}
+
+{{- /* Return the product info dict */ -}}
+{{- return dict
+ "product" $product
+ "version" $version
+ "isOSS" $isOSS
+ "productKey" $productKey
+ "productRef" $productRef
+ "productData" $productData
+ "pathSegments" $pathSegments
+-}}
diff --git a/layouts/shortcodes/api-endpoint.html b/layouts/shortcodes/api-endpoint.html
index 1203a87a4a..8dacbedbc8 100644
--- a/layouts/shortcodes/api-endpoint.html
+++ b/layouts/shortcodes/api-endpoint.html
@@ -1,13 +1,17 @@
-{{- $productPathData := findRE "[^/]+.*?" .Page.RelPermalink -}}
-{{- $currentVersion := index $productPathData 1 -}}
+{{- /* Get product info using baseURL-independent path detection */ -}}
+{{- $productInfo := partial "product-info.html" .Page -}}
{{- $endpoint := .Get "endpoint" -}}
-{{- $isOSS := ne (len (findRE `^v[0-9]` $currentVersion)) 0 -}}
-{{- $parsedProductKey := cond $isOSS "oss" $currentVersion -}}
-{{- $productKey := .Get "influxdb_host" | default $parsedProductKey -}}
-{{- $productAliases := dict "oss" "influxdb" "cloud" "influxdb_cloud" "cloud-tsm" "influxdb_cloud" "core" "influxdb3_core" "enterprise" "influxdb3_enterprise" "cloud-serverless" "influxdb3_cloud_serverless" "serverless" "influxdb3_cloud_serverless" "cloud-dedicated" "influxdb3_cloud_dedicated" "dedicated" "influxdb3_cloud_dedicated" "clustered" "influxdb3_clustered" -}}
-{{- $productRef := index $productAliases $productKey -}}
-{{- $productData := index .Site.Data.products $productRef -}}
-{{- $placeholderHost := $productData.placeholder_host }}
+{{- /* Allow influxdb_host parameter to override auto-detected product */ -}}
+{{- $overrideKey := .Get "influxdb_host" -}}
+{{- $productData := $productInfo.productData -}}
+{{- if $overrideKey -}}
+ {{- $productAliases := dict "oss" "influxdb" "cloud" "influxdb_cloud" "cloud-tsm" "influxdb_cloud" "core" "influxdb3_core" "enterprise" "influxdb3_enterprise" "cloud-serverless" "influxdb3_cloud_serverless" "serverless" "influxdb3_cloud_serverless" "cloud-dedicated" "influxdb3_cloud_dedicated" "dedicated" "influxdb3_cloud_dedicated" "clustered" "influxdb3_clustered" -}}
+ {{- $overrideRef := index $productAliases $overrideKey -}}
+ {{- if $overrideRef -}}
+ {{- $productData = index .Site.Data.products $overrideRef | default dict -}}
+ {{- end -}}
+{{- end -}}
+{{- $placeholderHost := $productData.placeholder_host | default "localhost:8086" }}
{{- $method := .Get "method" | upper -}}
{{- $methodStyle := .Get "method" | lower -}}
{{- $apiRef := .Get "api-ref" | default "" -}}
@@ -18,4 +22,4 @@
{{- else -}}
{{ $method }} {{ $renderedEndpoint }}
{{- end -}}
-
\ No newline at end of file
+
diff --git a/layouts/shortcodes/children.html b/layouts/shortcodes/children.html
index 1bea94f941..ed5d2772e7 100644
--- a/layouts/shortcodes/children.html
+++ b/layouts/shortcodes/children.html
@@ -42,14 +42,9 @@
{{ end }}
{{ end }}
{{ if .Params.list_code_example }}
- {{- $productPathData := findRE "[^/]+.*?" .Page.RelPermalink -}}
- {{- $currentVersion := index $productPathData 1 -}}
- {{- $isOSS := ne (len (findRE `^v[0-9]` $currentVersion)) 0 -}}
- {{- $productKey := cond $isOSS "oss" $currentVersion -}}
- {{- $productAliases := dict "oss" "influxdb" "core" "influxdb3_core" "enterprise" "influxdb3_enterprise" "cloud" "influxdb_cloud" "cloud-tsm" "influxdb_cloud" "cloud-serverless" "influxdb3_cloud_serverless" "serverless" "influxdb3_cloud_serverless" "cloud-dedicated" "influxdb3_cloud_dedicated" "dedicated" "influxdb3_cloud_dedicated" "clustered" "influxdb3_clustered" -}}
- {{- $productRef := index $productAliases $productKey -}}
- {{- $productData := index .Site.Data.products $productRef -}}
- {{- $placeholderHost := $productData.placeholder_host }}
+ {{- /* Get product info using baseURL-independent path detection */ -}}
+ {{- $productInfo := partial "product-info.html" $.Page -}}
+ {{- $placeholderHost := $productInfo.productData.placeholder_host | default "localhost:8086" }}
{{ .Params.list_code_example | replaceRE `\{\{[<\%] influxdb/host [>%]\}\}` $placeholderHost | .RenderString }}
{{ end }}
diff --git a/layouts/shortcodes/influxdb/host.html b/layouts/shortcodes/influxdb/host.html
index 0ed5f7b84c..bb60cd75df 100644
--- a/layouts/shortcodes/influxdb/host.html
+++ b/layouts/shortcodes/influxdb/host.html
@@ -1,9 +1,13 @@
-{{- $productPathData := findRE "[^/]+.*?" .Page.RelPermalink -}}
-{{- $currentVersion := index $productPathData 1 -}}
-{{- $isOSS := ne (len (findRE `^v[0-9]` $currentVersion)) 0 -}}
-{{- $parsedProductKey := cond $isOSS "oss" $currentVersion -}}
-{{- $productKey := .Get 0 | default $parsedProductKey -}}
-{{- $productAliases := dict "oss" "influxdb" "cloud" "influxdb_cloud" "cloud-tsm" "influxdb_cloud" "core" "influxdb3_core" "enterprise" "influxdb3_enterprise" "cloud-serverless" "influxdb3_cloud_serverless" "serverless" "influxdb3_cloud_serverless" "cloud-dedicated" "influxdb3_cloud_dedicated" "dedicated" "influxdb3_cloud_dedicated" "clustered" "influxdb3_clustered" -}}
-{{- $productRef := index $productAliases $productKey -}}
-{{- $productData := index .Site.Data.products $productRef -}}
-{{ $productData.placeholder_host }}
\ No newline at end of file
+{{- /* Get product info using baseURL-independent path detection */ -}}
+{{- $productInfo := partial "product-info.html" .Page -}}
+{{- /* Allow positional parameter to override auto-detected product */ -}}
+{{- $overrideKey := .Get 0 -}}
+{{- $productData := $productInfo.productData -}}
+{{- if $overrideKey -}}
+ {{- $productAliases := dict "oss" "influxdb" "cloud" "influxdb_cloud" "cloud-tsm" "influxdb_cloud" "core" "influxdb3_core" "enterprise" "influxdb3_enterprise" "cloud-serverless" "influxdb3_cloud_serverless" "serverless" "influxdb3_cloud_serverless" "cloud-dedicated" "influxdb3_cloud_dedicated" "dedicated" "influxdb3_cloud_dedicated" "clustered" "influxdb3_clustered" -}}
+ {{- $overrideRef := index $productAliases $overrideKey -}}
+ {{- if $overrideRef -}}
+ {{- $productData = index .Site.Data.products $overrideRef | default dict -}}
+ {{- end -}}
+{{- end -}}
+{{ $productData.placeholder_host | default "localhost:8086" }}