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 use IIS7, and say for example my site's URL is: http://example.com

Here is what I am trying to accomplish:

  1. All web pages go to WWW version.
  2. All HTTPS pages redirect to HTTP protocol except for example.com/foobar/
  3. If example.com/foobar has HTTP in front, force it to use HTTPS.

Therefore I have the following in my web.config file:

<rule name="Redirect to WWW" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^example.com$" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:0}" redirectType="Permanent" />
</rule>

<rule name="HTTPS to HTTP" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{SERVER_PORT}" pattern="^443$" />
<add input="{REQUEST_URI}" pattern="/foobar/" ignoreCase="true" negate="true" /> 
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
</rule>

<rule name="Force HTTPS on foobar" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{REQUEST_URI}" pattern="/foobar/"/> 
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
</rule>         

For some strange reason this won't work and the browser is telling me a redirect would never happen so an error page is thrown?

share|improve this question
    
Your last rule .. it will create infinite redirect since you do not check if you are already on HTTPS or not (you always redirect to secure protocol, even if you are already there). –  LazyOne Aug 24 '13 at 23:34
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.