0
votes

As title stated, I've a Wordpress multisite installation running several blogs under IIS. I need to force redirect from "http" to "https" but only for some of them. Blogs are typically reachable with and without 'www'. Let's say that I have the following blogs:

  • mickey.it
  • donald.it
  • daisy.it

and that only mickey and daisy run are https ready, I need a conditional rewrite condition to add to web.cofig

My web.config file has the typical Wordpress rewrite rules and not much more:

  <rules>
    <rule name="WordPress Rule 1" stopProcessing="true">
      <match url="^index\.php$" ignoreCase="false" />
      <action type="None" />
    </rule>
    <rule name="WordPress Rule 2" stopProcessing="true">
      <match url="^([_0-9a-zA-Z-]+/)?files/(.+)" ignoreCase="false" />
      <action type="Rewrite" url="wp-includes/ms-files.php?file={R:2}" appendQueryString="false" />
    </rule>
    <rule name="WordPress Rule 3" stopProcessing="true">
      <match url="^([_0-9a-zA-Z-]+/)?wp-admin$" ignoreCase="false" />
      <action type="Redirect" url="{R:1}wp-admin/" redirectType="Permanent" />
    </rule>
    <rule name="WordPress Rule 4" stopProcessing="true">
      <match url="^" ignoreCase="false" />
      <conditions logicalGrouping="MatchAny">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" />
      </conditions>
      <action type="None" />
    </rule>
    <rule name="WordPress Rule 5" stopProcessing="true">
      <match url="(^[_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*)" ignoreCase="false" />
      <action type="Rewrite" url="{R:2}" />
    </rule>
    <rule name="WordPress Rule 6" stopProcessing="true">
      <match url="^([_0-9a-zA-Z-]+/)?(.*\.php)$" ignoreCase="false" />
      <action type="Rewrite" url="{R:2}" />
    </rule>
    <rule name="WordPress Rule 7" stopProcessing="true">
      <match url="." ignoreCase="false" />
      <action type="Rewrite" url="index.php" />
    </rule>
  </rules>

Where and which new rule to apply (avoiding broke the existing ones)?

1

1 Answers

0
votes

Since the url rewrite module uses regex, i'm pretty sure something like this will get you going in the right direction.

<rule name="HTTP to HTTPS" enabled="true" stopProcessing="true">
    <match url=".*(mickey.it|donald.it).*" />
    <conditions>
        <add input="{HTTPS}" pattern="^OFF$" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />
</rule>

Could probably get fancier with the regex here, but it should be valid in the most basic sense.

I played around with it a bit and it seemed to work...