Configure URL rewriting
To ensure that relative links in HTML are rendered properly when integrating a rendering host with advanced Sitecore editors, Headless Services rewrites relative URLs in the returned markup to be absolute. The default tags and attributes included in this processing are as follows:
Tag name |
Attribute name |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Disable URL Rewriting
If you do not want Headless Services to rewrite relative URLs in the returned markup into absolute URLs, you can disable URL rewriting.
To disable URL rewriting:
-
In your app configuration, for the configured
http
render engine instance, change the value of the optionEnableRelativeLinkProcessing
tofalse
:RequestResponse<javaScriptServices> <renderEngines> <renderEngine name="http"> <instance id="RenderEngineInstance" inherits="defaults"> <EnableRelativeLinkProcessing>false</EnableRelativeLinkProcessing> </instance> </renderEngine> </renderEngines> </javaScriptServices>
Configure rewritten HTML attributes
You can customize URL rewrites by modifying the configuration for the rendering engine instance.
To configure rewritten HTML attributes:
-
In your app configuration, for your configured
http
rendering engine instance, in aLinkReplacement
element, specify the attributes used for link replacement usingLinkMap
elements. For example:RequestResponse<javaScriptServices> <renderEngines> <renderEngine name="http"> <instance id="RenderEngineInstance" inherits="defaults"> <LinkReplacement> <LinkMap tag="audio" attributes="src" /> <LinkMap tag="img" attributes="src, srcset" /> <LinkMap tag="link" attributes="href" /> <LinkMap tag="script" attributes="src" /> <LinkMap tag="source" attributes="src, srcset" /> <LinkMap tag="track" attributes="src" /> <LinkMap tag="video" attributes="src, poster" /> </LinkReplacement> </instance> </renderEngine> </renderEngines> </javaScriptServices>
Add a path to ignored paths
Some relative URL paths must not be rewritten by Headless Services. By default, these are:
-
-/media/
-
~/media/
-
-/jssmedia/
-
~/jssmedia/
To add a URL path to the ignored paths:
-
In your app configuration, for your configured
http
rendering engine instance, specify the ignored paths in anIgnoredPaths
element usingPath
elements. For example:RequestResponse<javaScriptServices> <renderEngines> <renderEngine name="http"> <instance id="RenderEngineInstance" inherits="defaults"> <IgnoredPaths> <Path>-/media/</Path> <Path>~/media/</Path> <Path>-/jssmedia/</Path> <Path>~/jssmedia/</Path> <Path>sitecore/shell/</Path> </IgnoredPaths> </instance> </renderEngine> </renderEngines> </javaScriptServices>