OR: How Do I Change My Site to Use HTTPS?
Now that you have an SSL certificate installed on your site, the natural question becomes how to make use of it. Just because it’s available doesn’t mean somehow magically it will be used. You need to take some steps to get it into use.
Search Engines
You don’t want to lose any of the page ranking gains you may have made. Google regards different URLs as different sites. The URL http://www.YourDomain.com is different than https://www.YourDomain.com, which is different than http://YourDomain.com. Among the first steps whenever you change a basic URL like this is to make sure Google understands that these are actually the same site. You can let them know by using the web master tools as described here:
https://support.google.com/webmasters/answer/83106?hl=en&ref_topic=6029673
Yahoo and Bing have similar tools which you most likely will want to use as well.
Apache .htaccess Files
RewriteEngine On
# Force www
RewriteCond %{HTTP_HOST} !^www.domain.com [NC]
RewriteRule ^(.*)$ https://www.domain.com/$1 [R=301,L]
# Force HTTPS
RewriteCond %{HTTPS} !=on
RewriteRule https://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L]
Replace domain.com with your domain name. The first rewrite condition and rule make sure that the site has been accessed using the www prefix. The part in brackets, R=301,L is what fires when the rule is matched and tells the web server to issue a 301 redirect to the https version of your site with the www. The “L” means “last rule”. The second part will fire if the site has been accessed using www, but not HTTPS.
Note: A 301 redirect is a permanent redirect. A 302 redirect is a temporary redirect. You may want to use 302 here during testing and change to 301 later. Browsers remember a 301 and will make the substitution before trying to access anything. This can cause a lot of confusion when minor mistakes are present.
Together, these rules will cause all accesses of your site to occur as https://www.YourDomain.com. Google recognizes a 301 redirect as a site URL change. This causes pages they have previously indexed which fall under the same URL to use the new one instead.
WordPress
Virtually all WordPress sites will want to have a 3rd section the .htaccess file above to allow for pretty URLs, using post names as access instead of numbered posts. If those rules are present, make them the last rule set.
If you are setting up a new WordPress site, get your certificate in place before installing WordPress! Doing so will save a lot of time later on.
Switching an existing wordpress site from http to https can be a challenge. The first step is to change the URL, which you can do in the settings section. But WordPress also embeds the URL in many places in posts, which sometimes leads to redirect loops getting set up. There are scripts available to go through the WordPress database, changing all occurrences of http to https.
Internal Page References
When you hand write or edit html code to include links to other pages on the same site or resources such as images, you don’t need to include a protocol specification such as
http:// or https://. Browsers understand that the reference is to the same site.
The main reason the protocol is sometimes specified is to make clear that the reference starts at the root of the site. Then if pages are moved around, no editing needs to be done. But even in those cases, you still don’t need the protocol. The reference can be written as for example: href=”//page.html”. By using 2 forward slashes, you are telling the browser to use the protocol it has been using to access the page, starting at the topmost level. This also makes the development process easier. Without a domain name and protocol, all the code is much more portable and reusable.
Take Credit Where Credit is Due!
At some appropriate place on your site, let your visitors know that you are enhancing their privacy by encrypting your site for them. Awareness of security on the Internet is rising, but is nowhere near where it should be. Any little boost you can give it is a good thing. You deserve credit for doing your part.