Combine HTTPS and WWW redirection rules

This doc brings two other docs together for those who need to implement both: Redirect HTTP to HTTPS and Fixing non-www redirection.

In order to achieve this you have to add the following MU plugin. The plugin will add the correct redirect rules to your htaccess file.

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:  wp-rocket-www-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

Open the file in a quality text editor and change all instances of example.com or example\.com to use your own domain name instead; then save the file.

4

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

5

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

Now all requests for non-WWW URLS on your site will be redirected to their WWW version, **and** all requests for HTTP URLs will be redirected to their HTTPS version.

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

# Redirect non-www to (ssl) www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
# Redirect non-SSL to SSL
RewriteCond %{HTTPS} !on
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.