{:en}Handle 301 redirects for .html extension and serve static html files too{:}{:ja}.html拡張子の301リダイレクトを処理し、静的htmlファイルも提供します{:}

{:en}I came across a scenario where my client wants to handle .html extensions. They want to create 301 for .html and also wanted to serve few html files as it is in our Sitecore application. My first thought was to create .html Handle into web configuration for handle .html extension. When I did so, I was able to handle .html extension for my 301 but was not able to serve static html files as IIS sends all .html extension to our application as we have a handler. We cannot redirect to the same URL for static files as it will be “too many redirects” as IIS will never serve static htmls. Then I tried to search for any pipeline if Sitecore have where it decides which extensions to serve. I found “CheckIgnoreFlag” pipeline where Sitecore decide if it is going to serve this type of extension or not. If not, It will return false else true.  
  <?xml version="1.0" encoding="utf-8"?>

  <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
  <pipelines>
  <httpRequestBegin>
  <processor patch:before="processor[@type='Sitecore.Pipelines.PreprocessRequest.CheckIgnoreFlag, Sitecore.Kernel']" type="[Namespace].Class, [Namespace]"/>
  </httpRequestBegin>
  </pipelines>
  </sitecore>
  </configuration>

  Here we will check for any extensions. So I create 301 Redirects here and if I don’t have any 301 Redirect for the incoming URL then I check if any physical file exists for the same path if it does I let Sitecore handle the things. Now Sitecore returns false to IIS that it cannot handle this URL. Then IIS tries to finds that physical file and it will redirects. If I don’t find any physical file on the same path, I redirect to our 404 page. By this way, we are able to handle 404 for different extensions too instead of showing IIS 404 page.  {:}{:ja}

クライアントが.html拡張子を処理したいというシナリオに出くわしました。 彼らは、.html用に301を作成し、Sitecoreアプリケーションのようにいくつかのhtmlファイルを提供したいと考えています。

私が最初に考えたのは、ハンドル.html拡張子のWeb構成に.htmlハンドルを作成することでした。

そうすると、301の.html拡張子を処理できましたが、ハンドラーがあるため、IISがすべての.html拡張子をアプリケーションに送信するため、静的なhtmlファイルを提供できませんでした。

IISが静的htmlを提供しないため、「リダイレクトが多すぎる」ため、静的ファイルの同じURLにリダイレクトすることはできません。

次に、Sitecoreが提供する拡張機能を決定する場所がある場合は、パイプラインを検索しようとしました。

Sitecoreがこのタイプの拡張機能を提供するかどうかを決定する「CheckIgnoreFlag」パイプラインを見つけました。提供しない場合はfalseを返し、そうでない場合はtrueを返します。

  <?xml version="1.0" encoding="utf-8"?>

  <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
  <pipelines>
  <httpRequestBegin>
  <processor patch:before="processor[@type='Sitecore.Pipelines.PreprocessRequest.CheckIgnoreFlag, Sitecore.Kernel']" type="[Namespace].Class, [Namespace]"/>
  </httpRequestBegin>
  </pipelines>
  </sitecore>
  </configuration>

ここでは、拡張機能を確認します。 そこで、ここで301リダイレクトを作成し、受信URLの301リダイレクトがない場合は、同じパスに物理ファイルが存在するかどうかを確認します。

Sitecoreに処理を任せます。 これで、SitecoreはこのURLを処理できないことをIISにfalseで返します。

次に、IISはその物理ファイルを見つけようとし、リダイレクトします。

同じパスに物理ファイルが見つからない場合は、404ページにリダイレクトします。

このようにして、IIS 404ページを表示する代わりに、さまざまな拡張機能の404を処理することもできます。

{:}

Leave a Reply

Create a website or blog at WordPress.com

Up ↑

Discover more from Sitecore Tales

Subscribe now to keep reading and get access to the full archive.

Continue reading