Configuring Custom Media Domain in Sitecore XP 10 + Next.js
Enabling Custom Domain URLs for Media Files in a Sitecore Headless (JSS + Next.js) Project
Recently, while working on a Sitecore XP 10 solution integrated with Next.js (JSS), I came across a requirement to serve media assets via a custom domain instead of the default Sitecore CM/CD URLs.
This is a common scenario when optimizing for performance, SEO, and CDN configurations — especially when you want to serve images from a brand-specific or region-specific domain like
https://Customdomain.com instead of the default https://sitecore-cd.azurewebsites.net.
Step 1: Define Media Base URL in Next.js
In your Next.js environment configuration, add a new variable to define the media domain:
This allows your front-end components to dynamically resolve Sitecore media URLs from the correct domain at runtime.
Step 2: Configure Site Definition in Sitecore
Next, you need to update the Sitecore site definition to use the same domain for generating media links.
In your Sitecore configuration (usually in App_Config/Include/Project/SiteDefinition.config or similar), add the following attribute inside your <site> node:
<site
name="brand-site"
hostName="branddomain.com"
rootPath="/sitecore/content/brand-site"
startItem="/home"
database="master"
mediaLinkServerUrl="https://Customdomain.com"
patch:source="Project.Brand.SiteDefinition.config" />
This ensures that when Sitecore generates media URLs (for example in Rich Text fields, image fields, or through the Layout Service), it uses your custom domain instead of the default one.
Result
Now, your Sitecore items and components in Next.js will load images from your custom domain:
instead of:
Final Thoughts
Using NEXT_PUBLIC_MEDIA_BASE_URL on the Next.js side and mediaLinkServerUrl in Sitecore’s site definition is a clean, environment-agnostic way to handle custom media domains.
It’s especially helpful when you have multiple sites or regions under one Sitecore instance sharing the same backend but different front-end domains.
Comments
Post a Comment