mercredi 6 mai 2020

Web.config redirect of both www and non-www to https

I had success redirecting www.example.com to https://example.com but not both www.example.com and example.com. Here's my code to redirect both:

<rewrite>
  <rules>
     <rule name="Force www and non-www" stopProcessing="true">
     <match url="(.*)" />
     <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
        <add input="{HTTP_HOST}{REQUEST_URI}" pattern="www.example.com" />
        <add input="{HTTP_HOST}{REQUEST_URI}" pattern="example.com" />
     </conditions>
     <action type="Redirect" url="https://example.com/{R:1}" redirectType="Permanent"/>
     </rule>
  </rules>
</rewrite>

It only seems to like the www option because it fails with either both www and non-www or just with non-www. Is there something wrong with the code?




Aucun commentaire:

Enregistrer un commentaire