How to redirect HTTPS to HTTP behind proxy (CloudFlare)
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)
Related videos on Youtube
Ankush Jain
Updated on September 18, 2022Comments
-
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 about 12 yearsPlease provide what you have tried first.
-
Alex about 12 yearsplease let us see your code and what way are you trying?
-
Admin almost 8 years"not worked" mean, It is not redirecting from https to http. yes website is accessible on port 443.
-
Admin almost 8 yearsActually I am using cloudflare for https
-
Admin almost 8 yearsAre you using the Flexible SSL (Free) cloudflare service?
-
Admin almost 8 yearsyes, I am using Flexible SSL (Free) cloudflare service
-
Admin almost 8 yearsDoes 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 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 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 about 12 years@Ankush: How does accepting an answer work?
-
Amit almost 8 yearsIf 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 almost 8 yearsThat 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 almost 8 yearsI've updated my answer with an alternative (.htaccess) solution.