Redirect HTTP to HTTPS

If you have SSL enabled for your entire site, you will need to make sure that all links pointing to the HTTP version of your site will be automatically redirected to the HTTPS version.

In order to achieve this you have to add the following MU plugin. The plugin will add the correct redirect rule to your htaccess file, and make sure that it always remains at the top for maximum efficiency.

1

Create a folder named mu-plugins in your wp-content folder.
In case a mu-plugins folder already exists, don’t create a new one, just use the existing one.

2

Download this PHP file to your computer: wprocket-https-redirect.php

Note: Use right-click (ctrl+click) and “save link as…” to make sure the file is downloaded (rather than opening it in the browser window).

3

Upload this file to the mu-plugins folder created in step 1.

4

Finally, make sure to deactivate and re-activate WP Rocket.

Now all requests for HTTP URLs on your site will be redirected to their HTTPS version.

These are the rules that the above MU plugin adds to the htaccess file:

# Redirect HTTP to HTTPS
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]