0

I am getting 404 when trying to access domain like https://www.example.com I get 404.

I have the following rewrite rules:

 <rules>
      <rule name="Redirect-HTTP-HTTPS-IIS">
  <match url="(.*)" />
  <conditions>
    <add input="{HTTPS}" pattern="^OFF$" ignoreCase="true" />
  </conditions>
  <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>

   <rule name="CanonicalHostNameRule1">
      <match url="(.*)"/>
      <conditions>
        <add input="{HTTP_HOST}" pattern="^example\.com$" negate="true"/>
      </conditions>
      <action type="Redirect" url="https://example.com/{R:1}"/>
    </rule>
  </rules>

Accessing https://www.example.com will get eventually to https://example.com. My problem is that some serves like Google webmaster tools validation can't verify the site because the page returns not found, although at the end it redirects to https://example.com.

http://example.com does show 301 redirect to https://example.com. It's only when I add www it doesn't show 301 redirect, although the server doe eventually redirects it to the right location.

How changes to the write rules I need to make so accessing https://www.example.com will be recognize as 301 redirect to https://example.com. I think that because of the multiple rules the page send not found.

Maybe there is a way to write it as a single rule that redirects 301 that includes both rules, so it will redirect URLs with HTTP or/and WWW to the one with HTTPS and non-WWW URLs.

Update: I inspected chrome Network and in the Status column, it say (canceled) for type Document and it shown on red. It might be due to IIS returning 404 because the HTTPS for domain with WWW is not certified. Is there any way around this?

Using IIS8.5 / ASP.NET 4.5

Thanks.

Liron Harel
  • 10,819
  • 26
  • 118
  • 217
  • http://stackoverflow.com/questions/33381095/how-to-dynamically-add-rules-to-iis-rewrite-map seems to be related with – Anil Mar 05 '17 at 18:11
  • @AnilKumar I don't think so, because on the client site in Chrome dev tools, in the 'status' column it say (canceled) for Type 'document) – Liron Harel Mar 05 '17 at 18:24
  • I think it's something that has to do with the Site binding – Liron Harel Mar 05 '17 at 18:35

1 Answers1

1

I needed to create an SSL certificate for the WWW version of the site as well. Once I did it, the redirection worked as intended.

Liron Harel
  • 10,819
  • 26
  • 118
  • 217