3

I have multiple domain names assigned to the same site and I want all possible access combinations redirected to one domain. In other words whether the visitor uses http://domainalias.ext or http://www.domainalias.ext or https://www.domainalias3.ext or https://domainalias4.ext or any other combination, including http://maindomain.ext, http://www.maindomain.ext, and https://www.maindomain.ext they are all redirected to https://maindomain.ext

I currently use the following code to partially achieve my objectives:

<?xml version="1.0" encoding="UTF-8"?>

<configuration>
    <system.webServer>
        <rewrite>
            <rules>

                <rule name="Redirect to https://MAINDOMAIN.EXT" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions logicalGrouping="MatchAny">
                        <add input="{HTTPS}" pattern="off" />
                        <add input="{HTTP_HOST}" pattern="^MAINDOMAIN\.EXT$" negate="true" />
                    </conditions>
                    <action type="Redirect" redirectType="Permanent" url="https://MAINDOMAIN.EXT/{R:1}" />
                </rule>

                <rule name="wordpress" patternSyntax="Wildcard">
                    <match url="*" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <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>

...but it fails to work in all instances. It does not redirect to https://maindomain.ext when user inputs https://(www.)domainalias.ext

So my question is, are there any programmers here familiar with IIS7 ReWrite that can help me modify my existing code to cover all possibilities and reroute all my domain aliases, loaded by themselves or using www in front, in HTTP or HTTPS mode, to my main domain in HTTPS format???

The logic would be: if entire URL does NOT start with https://maindomain.ext then REDIRECT to https://maindomain.ext/(plus_whatever_else_that_followed).

Thank you very much for your attention and any help would be appreciated.

NOTE TO MODS: If my question is not in the correct format, please edit or advise. Thanks in advance.

2
  • This might get answered more quickly over at serverfault
    – 93196.93
    Commented Sep 30, 2012 at 23:12
  • @Yottatron: Do you think this is a serverfault question? I would have said it was OK here or maybe on StackOverflow?
    – MrWhite
    Commented Oct 1, 2012 at 8:15

1 Answer 1

1

I believe this is a basic example of what you need to do:

<rewrite>
    <rules>
        <rule name="Redirect to maindomain.ext with SSL" stopProcessing="true">
            <match url="(.*)" />
            <conditions logicalGrouping="MatchAny">
                <add input="{HTTPS}" pattern="off" />
                <add input="{HTTP_HOST}" pattern="^maindomain.ext$" negate="true" />
            </conditions>
            <action type="Redirect" url="https://maindomain.ext" />
        </rule>
    </rules>
</rewrite>
4
  • Thank you for showing me how to group 2 rules into 1... I apprecialte that. However... the issue still remains. If the URL used by the visitor is already specified as https (instead of just http)... the redirect to https://maindomain.ext does not occur. And that is what I need... to be able to redirect both http and https requests to the single https://maindomain.ext
    – costax
    Commented Oct 7, 2012 at 7:41
  • Can you post the revised rule you are using? Is this rule being applied to your entire webserver or to just a specific website? It is possible there might be a rule conflict.
    – Rob
    Commented Oct 11, 2012 at 18:48
  • I did... I put up the entire file including the wordpress rule... just in case.
    – costax
    Commented Oct 13, 2012 at 5:17
  • I have tested your rule and it works as expected (although I didn't have WordPress installed). I did see a similar issue to what you describe where it appears that it does not redirect to the correct domain. In that test, I was using IE. As soon as I cleared my browsing history in the browser, it redirected as expected. You might want to make sure you delete any browser history and temporary internet files and see if that clears it up.
    – Rob
    Commented Oct 15, 2012 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.