1

I have installed WordPress on my IIS server and I also have the SSL Certificate installed.

I have researched every thread I could find on this, but still couldn't get it work. I found this thread from a guy on Apache who is facing the same issue, but I am on IIS and don't know how to get it to work with IIS.

Similar to that thread, here is what is happening:

https://www.example.com is working great

https://example.com is redirecting to the above, also great!

Here is the problem:

http://www.example.com is still accessible, no good, as this should redirect to https://www.example.com

Also:

http://example.com redirects to http://www.example.com.

How can I fix this, so that it all redirects to https://www.example.com?

I am on IIS and here is what my web.config looks like:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
        <rules>
            <rule name="WordPress Rule" stopProcessing="true">
                <match url=".*" />
                <conditions>
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                </conditions>
                <action type="Rewrite" url="index.php" />
            </rule>
        </rules>
        </rewrite>
    </system.webServer>
</configuration>
halfer
  • 19,824
  • 17
  • 99
  • 186
J86
  • 14,345
  • 47
  • 130
  • 228
  • 1
    Did you try [this](https://gist.github.com/tkarpinski/1621178)? – wpclevel May 08 '16 at 15:46
  • Will I add that rule in addition to the rule that already exists? If yes, does that new rule go before or after? – J86 May 08 '16 at 21:45
  • Last time I tried, all images on my site broke, I went ahead anyway and it worked. Thanks :) – J86 May 09 '16 at 06:40

2 Answers2

3

Thanks to Dan, this worked.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
        <rules>
      <rule name="HTTP to HTTPS redirect" stopProcessing="true">
        <match url="(.*)" />
      <conditions>
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
      </conditions>
      <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
    </rule>
            <rule name="WordPress Rule" stopProcessing="true">
                <match url=".*" />
                <conditions>
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                </conditions>
                <action type="Rewrite" url="index.php" />
            </rule>
        </rules>
        </rewrite>
    </system.webServer>
</configuration>
J86
  • 14,345
  • 47
  • 130
  • 228
0

First I would like to suggest you to get extension called “URL Rewrite” on your IIS.

Then you should match your code with the following code:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="HTTP/S to HTTPS Redirect" enabled="true" stopProcessing="true">
        <match url="(.*)" />
        <conditions logicalGrouping="MatchAny">
          <add input="{SERVER_PORT_SECURE}" pattern="^1$" />
          <add input="{SERVER_PORT_SECURE}" pattern="^0$" />
        </conditions>
        <action type="Redirect" url="https://{HTTP_HOST}/OWA/" redirectType="Permanent" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>