Sitecore SEO/Security rewrite rules


_config.yml List of Sitecore SEO / Security rewrite rules I recently added on CD nodes to one of the project.

SEO rewrite rules

Lower case

<rule name="Lower Case Rule" stopProcessing="true">
  <match url="[A-Z]" ignoreCase="false" />
    <add input="{REQUEST_METHOD}" matchType="Pattern" pattern="POST" ignoreCase="true" negate="true" />
    <add input="{URL}" pattern="^.*\.(axd|css|js|jpg|jpeg|png|gif|txt|xml|svg|pdf)$" negate="true" ignoreCase="true" />
  <action type="Redirect" url="{ToLower:{URL}}" />

Redirect to HTTPS

<rule name="HTTP to HTTPS redirect" stopProcessing="true">
  <match url="(.*)" />
    <add input="{HTTPS}" pattern="off" ignoreCase="true" />
  <action type="Redirect" url="https://{HTTP_HOST}/{R:1}"
      redirectType="Permanent" />

Security rewrite rules

Remove server header

<rule name="Removing server header" enabled="true">
  <match serverVariable="RESPONSE_SERVER" pattern=".*" />
  <action type="Rewrite" value="MyServer" replace="true" />

Add strict transport security

<rule name="Add Strict-Transport-Security when HTTPS" enabled="true">
  <match serverVariable="RESPONSE_Strict_Transport_Security"
      pattern=".*" />
    <add input="{HTTPS}" pattern="on" ignoreCase="true" />
  <action type="Rewrite" value="max-age=31536000" />

Happy Coding! 😇