How to Redirect HTTPS to HTTP with WP Rocket & WordPress

Here’s how to redirect all pages of your WordPress website or blog from HTTPS to HTTP when using the WP Rocket cache plugin.

This is not recommended however can be useful in some cases.

HTTPS to HTTP htaccess WordPress

First of all — it’s not possible to redirect from HTTPS to HTTP without a working TLS/SSL certificate for your WordPress website.

Choices are pretty much between (1) a self-signed TLS/SSL certificate or (2) a free domain validated certificate from Let’s Encrypt (supported by several hosting companies). Self-signed certs will be a hard time for users but search engine bots such as Google are able to crawl them; & they are supported by all cPanel hosting.

Secondly — within the Documentation for WP Rocket you will find a guide for achieving the very opposite. So in theory you could just change the code to reflect from HTTPS to HTTP. However I found that it’s much easier to add the code directly into your functions.php file as demonstrated below.

Here’s the code I used for functions.php:

add_filter( 'before_rocket_htaccess_rules', '__redirect_https' );
function __redirect_https( $marker ) {
 $redirection = '# Redirect https to http' . PHP_EOL;
 $redirection .= 'RewriteEngine On' . PHP_EOL;
 $redirection .= 'RewriteCond %{HTTP} !on' . PHP_EOL;
 $redirection .= 'RewriteCond %{SERVER_PORT} ^443$' . PHP_EOL;
 $redirection .= 'RewriteCond %{HTTP:X-Forwarded-Proto} !http' . PHP_EOL;
 $redirection .= 'RewriteRule ^(.*)$ http://%{HTTPS_HOST}/$1 [R=301,L]' . PHP_EOL;
 $redirection .= '# END http redirect' . PHP_EOL . PHP_EOL;
 $marker = $redirection . $marker;
 return $marker;
}

Please note that you will need to deactivate and activate WP Rocket for the changes to take effect (htaccess mended).

Don’t have WP Rocket?

This is the code the function will add to the very top of your .htaccess file. You may want to use it directly if you wish.

# Redirect https to http
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^webhostwhat\.com$
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI} [R,L]
# END https redirect

 

Thanks & questions welcome as always!

Dave Walls

1 thought on “How to Redirect HTTPS to HTTP with WP Rocket & WordPress”

Leave a Reply to S M Nahid Emon Cancel reply

css.php