How to redirect HTTPS to HTTP behind proxy (CloudFlare)

343

yes, I am using Flexible SSL (Free) cloudflare service

This is the "problem". As Antony suggests in comments. Your server is responding to requests on port 80 (plain HTTP). The SSL connection is only between the visitor and CloudFlare. The connection between CloudFlare and your server is not encrypted. This is what the "Flexible SSL" (Free) CloudFlare service is.

Reference:
https://support.cloudflare.com/hc/en-us/articles/200170416-What-do-the-SSL-options-mean-

Since you seem to want to redirect all requests to HTTP, then you should disable the SSL option at CloudFlare.


UPDATE: Since your server is working on plain HTTP and the SSL is being handled by the front end proxy (CloudFlare in this case) then the only way to detect the protocol of the original request (ie. HTTP or HTTPS) is if the proxy sends this information in an HTTP request header, ie. X-Forwarded-Proto by convention.

From Wikipedia - List of HTTP header fields - X-Forwarded-Proto:

a de facto standard for identifying the originating protocol of an HTTP request, since a reverse proxy (or a load balancer) may communicate with a web server using HTTP even if the request to the reverse proxy is HTTPS.

Incorporating this into an HTTPS to HTTP redirect:

RewriteCond %{HTTP:X-Forwarded-Proto} =https [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

Reference:
Cloudflare Support - How do I fix the infinite redirect loop error after enabling Flexible SSL with WordPress? (includes relevant non-WordPress information)

Share:
343

Related videos on Youtube

Ankush Jain
Author by

Ankush Jain

Updated on September 18, 2022

Comments

  • Ankush Jain
    Ankush Jain over 1 year

    I am unable to bind a dropdownlist to list dictionary collection(in code behind) at runtime. Dropdownlist is inside a formview's insertitemtemplate. Please provide solutions.

    • Sani Singh Huttunen
      Sani Singh Huttunen about 12 years
      Please provide what you have tried first.
    • Alex
      Alex about 12 years
      please let us see your code and what way are you trying?
    • Admin
      Admin almost 8 years
      "not worked" mean, It is not redirecting from https to http. yes website is accessible on port 443.
    • Admin
      Admin almost 8 years
      Actually I am using cloudflare for https
    • Admin
      Admin almost 8 years
      Are you using the Flexible SSL (Free) cloudflare service?
    • Admin
      Admin almost 8 years
      yes, I am using Flexible SSL (Free) cloudflare service
    • Admin
      Admin almost 8 years
      Does cloudflare behave like a proxy? Meaning it receives a call on https and then forward it to the http. Then RewriteCond %{SERVER_PORT} ^443$ will never be true as apache only receives a http call. You would need to look into something like X-Forwarded-For headers.
  • Mubarek
    Mubarek about 12 years
    @AnkushJain the rule is you mark the answer as accepted/answered if it satisfies you, so that other users with the same problem will benefit from it. And upvoting means : The answer is useful nothing more ! you can find these buttons on the top left corner of the answer
  • Ankush Jain
    Ankush Jain about 12 years
    @nuux - thank you nuux but i can't vote until i get 15 reoutation and second thing i am not getting where is option for accepted/ marked ?
  • Tim Schmelter
    Tim Schmelter about 12 years
  • Amit
    Amit almost 8 years
    If I disable the SSL, then https urls redirects to 404 page. Actually I am using shared cloud hosting. So to fix 404 errors, I used Flexible SSL cloudflare. I cannot use https because website contains mixed content (both https,http images and iframe) and https urls blocks all http content
  • MrWhite
    MrWhite almost 8 years
    That 404 page is presumably generated by CloudFlare? Why is a 404 bad in this instance? (In other environments you'd simply get a security error.) Do you have a number of indexed (or erroneously linked to) HTTPS pages? Unfortunately, I'm not aware of a solution that can be used at your server. As far as your server is concerned it is already serving content over HTTP://...?
  • MrWhite
    MrWhite almost 8 years
    I've updated my answer with an alternative (.htaccess) solution.