简体   繁体   中英

Azure redirect non-www to www

I have question about Azure redirection.

I have searched other topics but not quite my problem(s).

I have ASP.NET Core 2.2 project and Azure configured for that. Also i have domain for pointing to Azure. I have added www.example.com format domain to azure and that works fine also with https.

Problem rises with example.com format

I wanted to redirect example.com format to www.example.com URL

I manage to get this work with this, but for little while. I use this web.config for redirection

web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <rewrite>
      <rules>
        <rule name="CanonicalHostNameRule" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^example.com$" />
          </conditions>
          <action type="Redirect" url="https://www.example.com/{R:0}" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

Something strange is Google Chrome & Opera redirect(s) to www domain but not Edge and Firefox. Then when i clear cache(s) then it wont redirect.

Seems like Azure like rewrites some over or something.

Thanks for help!!

In addition to the web.config file changes, ensure the Azure Website instance contains the correct domain bindings within the Hostname bindings area.

<rule name="Redirect to www">
  <match url=".*" />
  <conditions logicalGrouping="MatchAny">
    <add input="{HTTP_HOST}" pattern="^example.com$" negate="true" />
  </conditions>
  <action type="Redirect" url="http://www.example.com/{R:0}" redirectType="Permanent"/>
</rule>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM