Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I had a standard website hosted on a server I have full control over - www.domain.com. I recently purchased an SSL certificate for this domain in preparation for accepting credit cards and am looking to have all requests redirect to https://www.domain.com. For the most part, the rule I created (see below) works fine - if I type in http://www.domain.com it'll redirect to https://www.domain.com. The problem I have is if I go to an inner link, such as http://www.domain.com/folder/page.aspx, I get a 404 because the only binding ties to HTTPS. How can I make a redirect rule that says any request for www.domain.com gets sent to HTTPS, but retain the original folder/page structure that was requested? So, going to http://www.domain.com/folder/page.aspx sends me to https://www.domain.com/folder/page.aspx. I'd prefer if query string values also stayed intact.

Here is my current rewrite rule:

   <rewrite>
        <rules>
            <rule name="Redirect to HTTPS" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTPS}" pattern="^OFF$" />
                </conditions>
                <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
            </rule>
        </rules>
    </rewrite>
share|improve this question

2 Answers 2

up vote 2 down vote accepted

I ended up solving it on my own - I did a combination of two different rules (one to rewrite http://domain.com to https://www.domain.com where the cert is linked to) and another to just redirect all HTTPS requests and it seems to be working perfectly. Here is the relevant config entry:

   <rewrite>
        <rules>
            <rule name="CanonicalHostNameRule1">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTP_HOST}" pattern="^www\.domain\.com$" negate="true" />
                </conditions>
                <action type="Redirect" url="http://www.domain.com/{R:1}" />
            </rule>
            <rule name="Redirect to HTTPS" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTPS}" pattern="^OFF$" />
                </conditions>
                <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
            </rule>
        </rules>
    </rewrite>
share|improve this answer

I know that you can take the entire URL with you if you configure redirects within IIS, if you use the attribute appendUrlTrail="true". Maybe you could append it to the Tag. I'm not sure whether it is working or not :-)

share|improve this answer
    
I can't seem to find any reference to that tag on Bing, Google or doing an MSDN search directly. Where does it go? –  digitall Nov 30 '12 at 21:13
    
Neither did I. But I thought it was this attribute. I will have a look to the system on monday and tell you the exact configuration. –  Andre Fritsche Dec 1 '12 at 6:12

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.