Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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.

share|improve this question
    
This might get answered more quickly over at serverfault –  Yottatron Sep 30 '12 at 23:12
    
@Yottatron: Do you think this is a serverfault question? I would have said it was OK here or maybe on StackOverflow? –  w3d Oct 1 '12 at 8:15
add comment

1 Answer

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>
share|improve this answer
    
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 Oct 7 '12 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 Oct 11 '12 at 18:48
    
I did... I put up the entire file including the wordpress rule... just in case. –  costax Oct 13 '12 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 Oct 15 '12 at 16:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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