WordPress redirect https to http without SSL certificate

If your website has an invalid SSL certificate for your site (perhaps your shared hosting company has a wildcard certificate), most browsers will show a warning about the validity of the certiticate.

However, Google could still index your site using https: URLs, as it assumes you have a valid SSL certificate.

The problem is, if people click the links from Google, they get the browser warning.

Changes to your htaccess file wont work as.

Here is a php snippet you can drop into your theme functions.php. It redirects at the PHP level.

// Avoid SSL on Google
add_action( 'template_redirect', 'bhww_ssl_template_redirect', 1 );
function bhww_ssl_template_redirect() {
  $https = ( $_SERVER['HTTP_X_HTTPS'] == 'On' );
  if ( $https ) {
    if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) {
      wp_redirect( preg_replace( '|^https://|', 'http://', $_SERVER['REQUEST_URI'] ), 301 );
      exit();
    } else {
      wp_redirect( ‘http://’ . $_SERVER[‘HTTP_HOST’] . $_SERVER[‘REQUEST_URI’], 301 );
      exit();
    }
  }
}

Leave a Comment

Your email address will not be published. Required fields are marked *