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:
-
For the configured
httprender engine, change the value of the optionEnableRelativeLinkProcessingtofalse:
Configure rewritten HTML attributes
You can customize URL rewrites by overriding the type Sitecore.JavaScriptServices.ViewEngine.Http.RenderEngineOptionsResolver.
To configure rewritten HTML attributes:
-
Reference the nuget package
Sitecore.JavaScriptServices.ViewEngine.Http. -
Create a type that inherits the type
Sitecore.JavaScriptServices.ViewEngine.Http.RenderEngineOptionsResolver. -
Override the
ResolveAllandResolveForId. -
Override the
LinkAttributeMapfield of options returned by the base method: -
Create a dependency configurator and override the
IRenderEngineOptionsResolverservice registration: -
Create a config patch with the following patch:
-
Deploy the custom assembly and configuration patch to your Sitecore instance.
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/
Adding or removing paths can be done by overriding the type Sitecore.JavaScriptServices.ViewEngine.Http.RenderEngineOptionsResolver .
To add a URL path to the ignored paths:
-
Reference the nuget package
Sitecore.JavaScriptServices.ViewEngine.Http. -
Create a type that inherits the type
Sitecore.JavaScriptServices.ViewEngine.Http.RenderEngineOptionsResolver. -
Override the
ResolveAllandResolveForId. -
Override the
LinkAttributeMapfield of options returned by the base method: -
Create a dependency configurator and override the
IRenderEngineOptionsResolverservice registration: -
Create a config patch with the following patch:
-
Deploy the custom assembly and configuration patch to your Sitecore instance.