HTTPS redirects are to redirect HTTP visitors to HTTPS:
- For example…if someone visits your site using
http://yourdomain.com
, they get redirected tohttps://yourdomain.com
The easiest way to enable HTTPS redirect on our service is to go to Site settings > Security TAB > HTTPS Redirect, and toggle [ENABLED]. Everything is done!
- If this is for a new site or an old site (that always had HTTPS), that’s all you have to do.
- If this is for an old site that just recently got switched to HTTPS, you should probably check all steps in this guide.
- If you want to nerd out or learn about putting these redirects manually in your haccess, please continue reading below.
I’ve given examples for both “www” and also “without www”. Add this code (use either version of either method) above the #BEGIN WordPress line in your htaccess.
Method #1
This one uses less code but has more redirects when you use page tools. It works well but perhaps less performant than the 2nd.
WITHOUT www (all visits go to “https://domain.com”):
#301 https redirects
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
WITH www (all visits go to “https://www.domain.com”):
#301 https redirects
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Method #2
An alternate method, thanks to Nazar Hotsa who’s researched every method and shared this with me. Awesome community guy with tons of enterprise webhosting experience.
WITHOUT www (all visits go to “https://domain.com”):
# BEGIN Redirects
RewriteEngine On
# 301 redirect www to non-www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
# 301 redirect to https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# END Redirects
WITH www (all visits go to “https://www.domain.com”):
# BEGIN Redirects
RewriteEngine On
# 301 redirect to www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# 301 redirect to https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# END Redirects
Other ways to redirect?
Some people complained my examples used too many redirects. In that case, you’re welcome to research on your own and try other methods of redirection.
Read below and see which one you like best (beware, they all have their implications):
- https://simonecarletti.com/blog/2016/08/redirect-domain-http-https-www-apache/
- https://www.codexworld.com/redirect-non-www-to-www-http-to-https-using-htaccess-file/
- https://www.digitalocean.com/community/questions/redirect-http-https-www-to-https-non-www
- https://stackoverflow.com/questions/13977851/htaccess-redirect-to-https-www
- https://serverfault.com/questions/523199/redirect-all-http-and-https-non-www-urls-to-https-www-example-com-via-htaccess
- https://wpjohnny.com/301-redirects-to-https-with-and-without-www/ (original guide)