4

I want to redirect HTTPs to HTTP, I tried following code in .htaccess file

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]

I also tried the following code in .httaccess file, which also did not work.

Options +FollowSymlinks

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{SERVER_PORT} ^443$
    RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]

    # BEGIN WordPress
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    # END WordPress
</IfModule>

I also tried a few HTTPS to HTTP WordPress plugins as well, which also did not work.

Please guide me on how can I resolve this issue.

migrated from wordpress.stackexchange.com May 24 '16 at 8:16

This question came from our site for WordPress developers and administrators.

  • 1
    What exactly does "not worked" mean? Is your site accessible on port 443? Presumably .htaccess / mod_rewrite is enabled and does something? – MrWhite May 24 '16 at 8:30
  • "not worked" mean, It is not redirecting from https to http. yes website is accessible on port 443. – Amit May 24 '16 at 8:42
  • Actually I am using cloudflare for https – Amit May 24 '16 at 8:44
  • 1
    yes, I am using Flexible SSL (Free) cloudflare service – Amit May 24 '16 at 9:29
  • 1
    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. – Antony Gibbs May 24 '16 at 10:48
2

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)

  • 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 – Amit May 24 '16 at 12:09
  • 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 May 24 '16 at 15:06
  • I've updated my answer with an alternative (.htaccess) solution. – MrWhite Jun 6 '16 at 23:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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