5

I am working on Sitecore project and using 301 redirect for our website. Right now our redirect chain is

http://example.com/ >> http://www.example.com >> https://www.example.com >> https://www.example.com/en

Our company recommendation is to change it in one redirect Example.

http://example.com/ >> https://www.example.com/en

http://www.example.com >> https://www.example.com/en

https://www.example.com >> https://www.example.com/en

Is there any way that I can achieve this requirement with Sitecore or IIS URL Rewrite? If yes then How? Thank you for any small help.

3 Answers 3

7

Yes, You can achieve this requirement through Sitecore 301 Redirect Module or IIS URL Rewrite both.

Paste the below Code inside your <system.webServer></system.webServer> element in the web.config

<rewrite>
  <rules>
    <rule name="Redirect Maps Rule" stopProcessing="true">
      <match url=".*" />
      <conditions>
        <add input="{StaticRedirects:{PATH_INFO}}" pattern="(.+)" />
      </conditions>
      <action type="Redirect" url="{C:1}" appendQueryString="True" redirectType="Permanent" />
    </rule>
  </rules>
  <rewriteMaps>
    <rewriteMap name="StaticRedirects">
      <add key="http://example.com" value="https://www.example.com/en" />
<add key="http://www.example.com" value="https://www.example.com/en" />
<add key="https://www.example.com" value="https://www.example.com/en" />

    </rewriteMap>
  </rewriteMaps>
</rewrite>

Below is the link, from where you can easily generate the IIS 301 redirection rules online :

http://iis7-rewrite.herokuapp.com

I hope this will help you.

9

Well in any case you will have to bind example.com as well as www.example.com on your website.

Next you have multiple options. Either use IIS Rewrite rules.

<rule name="Root Hit Force HTTPS Redirection" enabled="true" stopProcessing="true">
  <match url="^$" ignoreCase="false" />
  <conditions>
    <add input="{HTTPS}" pattern="^OFF$" />
    <add input="{HTTP_METHOD}" pattern="GET" />
  </conditions>
  <action type="Redirect" url="https://{HTTP_HOST}/" redirectType="Permanent" />
</rule>

and for www redirection

<rule name="Redirect example.com to www" stopProcessing="true">
  <match url="^(.*)" />
  <conditions>
    <add input="{HTTP_HOST}" pattern="^example\.com$" />
  </conditions>
  <action type="Redirect" url="https://www.example.com/{R:0}" redirectType="Permanent" />
</rule>

Another possibility is to use the redirect module that comes with SXA.

And finally, you could use something from the marketplace. https://marketplace.sitecore.net/en/Modules/3/301_Redirect_module.aspx

1

You can write your own re-write rule:

https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module

It is not related to the Sitecore. If you want to handle inside the Sitecore, you have to use rewrite rule module available on the Sitecore Marketplace.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.