Redirect https website to http

Asked

Viewed 8,320 times

8

I currently have a site where uses an SSL certificate, as the certificate has expired and it needs to be renewed, SSL error occurs in any browser making users' visits impossible.

I’d like to redirect traffic https:// to the standard http:// using the .htaccess.

  • Try with this rule, make sure that mod_rewrite is enabled.

  • 2

    Remembering that anyway, there will be an initial error, because the negotiation of SSL (the secure connection of https) will occur before the HTTP request itself, therefore, before the redirect. This is why each site with SSL usually needs a separate IP for each domain, while the HTTP 426 method is not common for hosting. (this number I memorized, reminds me of LV-426 :P )

  • Usually the hosts that are shared use shared ssl, as it comes out much more into account.

2 answers

10


Here it is in PHP as you wish: ( reply edited by @Bacco)

<?php
function ForceHTTP() {
    if ($_SERVER['HTTPS'] == "on") {
        $url = $_SERVER['SERVER_NAME'];
        $new_url = "http://" . $url . $_SERVER['REQUEST_URI'];
        header("Location: $new_url");
        exit;
    }
}
?>

Don’t forget to "call" the function:

<?php ForceHTTP(); ?>

Or with .htaccess to always open in HTTP://

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Or with .htaccess to always open in HTTPS:// (which is how I use on my website):

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  • Reply updated @Bacco

  • Okay, thanks. hehehe' ended up helping me too.

  • Well, that’s where my doubt was, show!

6

Try it this way, I think it solves your problem. Add these lines to your . htaccess:

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
  • 3

    Hi, Miguel, Welcome to [pt.so]. The cool thing is to explain why your solution works and as works. Check out the guide [Answer].

  • Thanks @Miguel, solve my problem!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.