Force HTTPS and/or WWW on your WordPress site!

As you probably know by now. Google is starting to add a new ranking factor to their ever-changing algorithm.

It’s SSL that they want us to use but it’s a good thing since the data you send and receive from a server will be encrypted and a bit harder for people that might try to gather information like credit card numbers, passwords and other sensitive information.

First, make sure you’re happy with your Permalinks settings. Once that is done, open the file named “.htaccess” and after taking a backup of it, change it to the similar bit of “code” below:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# Force www
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# Force SSL
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L,NE]
</IfModule>
# END WordPress

Just add the “Force www” part for adding www if you want it. The SSL part below is what’s important.

Save the file and try going to some of your old URLs.