---
title: "URL書き換えの設定"
slug: "configure-url-rewriting"
abstract: "Sitecoreエディターとレンダリングホストを統合する際のURL書き換えのカスタマイズ"
---
# URL書き換えの設定

HTMLの相対リンクが高度なSitecoreエディタと統合される際に適切にレンダリングされるようにするため、Headless Servicesは返還されたマークアップ内の相対URLを絶対的なURLに書き換えます。この処理に含まれるデフォルトのタグと属性は以下の通りです。

タグ名

属性名

audio

src

img

src, srcset

link

href

script

src

source

src, srcset

track

src

video

poster, src

## URL書き換えを無効にする

Headless Servicesが返されるマークアップ内の相対的なURLを絶対URLに書き換えたくない場合は、URL書き換えを無効にできます。

URL書き換えを無効にするには:

-   設定済みのhttpレンダリングエンジンでは、オプションEnableRelativeLinkProcessingの値をfalseに変更してください:
    
    <javaScriptServices>
     <renderEngines>
     <renderEngine name="http">
     <instance id="RenderEngineInstance" inherits="defaults">
     <EnableRelativeLinkProcessing>false</EnableRelativeLinkProcessing>
     </instance>
     </renderEngine>
     </renderEngines>
    </javaScriptServices>
    

## 書き換えたHTML属性の設定

URLの書き換えは型Sitecore.JavaScriptServices.ViewEngine.Http.RenderEngineOptionsResolverを上書きすることでカスタマイズできます。

書き換えたHTML属性を設定するには:

1.  nugetパッケージを参照Sitecore.JavaScriptServices.ViewEngine.Http。
    
2.  型Sitecore.JavaScriptServices.ViewEngine.Http.RenderEngineOptionsResolverを継承する型を作成します。
    
3.  ResolveAllを上書きしてResolveForId。
    
4.  基本メソッドで返されたLinkAttributeMapオプションフィールドを上書きします:
    
    public override IEnumerable<HttpRenderEngineOptions> ResolveAll(RenderEngineOptions runtimeOptions = null)
     {
     var optionsCollection = base.ResolveAll(runtimeOptions);
     foreach (var options in optionsCollection)
     {
     options.LinkAttributeMap.Add("video", new { "poster", "src" });
     }
    
     return optionsCollection;
     }
    
     public override HttpRenderEngineOptions ResolveForId(string id, RenderEngineOptions runtimeOptions = null)
     {
     var options = base.ResolveForId(id, runtimeOptions);
     options.LinkAttributeMap.Add("video", new { "poster", "src" });
     return options;
     }
    
5.  依存関係構成器を作成し、IRenderEngineOptionsResolverサービス登録をオーバーライドします:
    
    public void Configure(IServiceCollection serviceCollection)
     {
     serviceCollection.AddTransient<IHttpRenderEngineFactory, HttpRenderEngineFactory>();
     serviceCollection.AddTransient<IConfigurationReader, XmlConfigurationReader>();
     serviceCollection.AddSingleton<IHttpSessionStateResolver, HttpSessionStateResolver>();
     serviceCollection.AddTransient<IOverrideOptionsResolver, OverrideOptionsResolver>();
     serviceCollection.AddSingleton<IRenderEngineOptionsResolver, CustomRenderEngineOptionResolver>();
     serviceCollection.AddTransient<IHttpClientFactory, HttpClientFactory>();
     }
    
6.  以下のパッチで設定パッチを作成してください:
    
    <services>
     <configurator patch:instead="configurator@type='Sitecore.JavaScriptServices.ViewEngine.Http.RegisterDependencies, Sitecore.JavaScriptServices.ViewEngine.Http'" type="<CustomTypeName>, <CustomAssembly>" />
     </services>
    
7.  カスタムアセンブリと設定パッチをSitecoreインスタンスにデプロイしてください。
    

## 無視された経路にパスを追加します

一部の相関URLパスはヘッドレスサービスによって書き換えられません。デフォルトでは以下の通りです:

-   \-/media/
-   ~/media/
-   \-/jssmedia/
-   ~/jssmedia/

パスの追加または削除は型Sitecore.JavaScriptServices.ViewEngine.Http.RenderEngineOptionsResolverをオーバーライドすることで行えます。

無視されたパスにURLパスを追加するには:

1.  nugetパッケージを参照Sitecore.JavaScriptServices.ViewEngine.Http。
    
2.  型Sitecore.JavaScriptServices.ViewEngine.Http.RenderEngineOptionsResolverを継承する型を作成します。
    
3.  ResolveAllを上書きしてResolveForId。
    
4.  基本メソッドで返されたLinkAttributeMapオプションフィールドを上書きします:
    
    public override IEnumerable<HttpRenderEngineOptions> ResolveAll(RenderEngineOptions runtimeOptions = null)
     {
     var optionsCollection = base.ResolveAll(runtimeOptions);
     foreach (var options in optionsCollection)
     {
     options.IgnoredPaths.Add("sitecore/shell/");
     }
    
     return optionsCollection;
     }
    
     public override HttpRenderEngineOptions ResolveForId(string id, RenderEngineOptions runtimeOptions = null)
     {
     var options = base.ResolveForId(id, runtimeOptions);
     options.IgnoredPaths.Add("sitecore/shell/");
     return options;
     }
    
5.  依存関係構成器を作成し、IRenderEngineOptionsResolverサービス登録をオーバーライドします:
    
    public void Configure(IServiceCollection serviceCollection)
     {
     serviceCollection.AddTransient<IHttpRenderEngineFactory, HttpRenderEngineFactory>();
     serviceCollection.AddTransient<IConfigurationReader, XmlConfigurationReader>();
     serviceCollection.AddSingleton<IHttpSessionStateResolver, HttpSessionStateResolver>();
     serviceCollection.AddTransient<IOverrideOptionsResolver, OverrideOptionsResolver>();
     serviceCollection.AddSingleton<IRenderEngineOptionsResolver, CustomRenderEngineOptionResolver>();
     serviceCollection.AddTransient<IHttpClientFactory, HttpClientFactory>();
     }
    
6.  以下のパッチで設定パッチを作成してください:
    
    <services>
     <configurator patch:instead="configurator@type='Sitecore.JavaScriptServices.ViewEngine.Http.RegisterDependencies, Sitecore.JavaScriptServices.ViewEngine.Http'" type="<CustomTypeName>, <CustomAssembly>" />
     </services>
    
7.  カスタムアセンブリと設定パッチをSitecoreインスタンスにデプロイしてください。