Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iis url redirect http to non www https

Tags:

redirect

iis

web

i need to redirect from

www.domain.de to https://domain.de -works

http://www.domain.de to https://domain.de -works

http://domain.de to https://domain.de -does not work

rewrite>
  <rules>
    <rule name="Imported Rule 1" stopProcessing="true">
      <match url="^(.*)$" ignoreCase="false" />
      <conditions logicalGrouping="MatchAll">
        <add input="{HTTP_HOST}" pattern="^www\.(.+)$" />
      </conditions>
      <action type="Redirect" url="https://{C:1}/{R:1}" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>
like image 781
Marius Krämer Avatar asked Jun 14 '13 14:06

Marius Krämer


1 Answers

I think this will work for you, the search pattern has the optional www and redirects using the back reference C:2, the rule has a condition to only run against non https.

This is the pattern:

"^(www\.)?(.*)$"

where:

{C:0} - www.domain.de
{C:1} - www.
{C:2} - domain.de

Here's the rule in full:

  <rewrite>
    <rules>
      <rule name="SecureRedirect" stopProcessing="true">
        <match url="^(.*)$" />
        <conditions>
          <add input="{HTTPS}" pattern="off" />
          <add input="{HTTP_HOST}" pattern="^(www\.)?(.*)$" />
        </conditions>
        <action type="Redirect" url="https://{C:2}" redirectType="Permanent" />
      </rule>
    </rules>
  </rewrite>
like image 146
David Martin Avatar answered Sep 20 '22 23:09

David Martin