HTTP to HTTPS, to understand how to redirect website traffic from HTTP to HTTPS, first, we will give a brief about what is HTTP and HTTPS. Let’s start it.
You might see some websites running over HTTP and some are over HTTPS. The reason for this is the hero of the story which is the SSL certificate which is described in our blog check it out.
HTTPS is a protocol for secure communication over a computer network that is widely used on the Internet. More and more website owners are migrating from HTTP to HTTPS, mainly due to the 5 following reasons:
- Google announced that sites using HTTPS will get a slight ranking factor in Google search.
- You can achieve faster performance with the new HTTP/2 protocol which requires HTTPS due to browser support. And yes, Kinsta supports HTTP/2 on all servers.
- HTTPS is more secure and your visitor’s data is entirely encrypted.
- HTTPS can build trust by enabling the green padlock in the visitor’s web browser address bar.
- If someone is visiting a website from HTTPS and going to an HTTP website, the referral data is lost in Google Analytics. It usually ends up lumped together with the “direct traffic.” If someone goes from an HTTPS website to another HTTPS website, the referral data is still passed. So by migrating from HTTP to HTTPS, you can actually have more accurate referral data.
HTTP: In the early days, a protocol was designed which was a hypertext transfer protocol aka HTTP to communicate from browser to web server. But eventually, a lot of hackers and attackers came across which was alarming and threatening for users cause whenever data transfer through HTTP protocol, it travels in simple clear text format. So it was highly required to encrypt data while communicating both ways web server and a web browser through a secured protocol as sensitive data like credit card information, logging information, and a whole bunch of data that needs to be encrypted. Here comes the secured protocol HTTPS aka Hypertext Transfer Protocol Secure. The main reason to launch this protocol was to encrypt data and ensure security while transferring data from the web server to the web browser.
Automatically Redirect Your WordPress Website’s Traffic from HTTP to HTTPS in WordPress Admin Area:
After your SSL certificate is installed on your hosting account, there are some modifications you’ll need to make as follows:
- Add HTTPS to the
Open wp-config.php in your WordPress root folder and add the following line somewhere before where it says That’s all, stop editing!. to your .htaccess file. Adding a few lines to your .htaccess file will automatically redirect your visitors to the HTTPS version of your website.
define(‘FORCE_SSL_ADMIN’, true);
Once you have updated the file, it’s time to test if it works. For that, try to access your login page with HTTPS in the URL, for example via https://yoursite.com/wp-admin. If everything worked correctly, you should have a secure connection now. Then continue.
- Update the Site Address:
After moving the WordPress backend over to HTTPS, it’s time to do the same for the remainder of your site. You can do that by updating your site address under Settings > General.
Automatically Redirect Your WordPress Website’s Traffic from HTTP to HTTPS in cPanel:
- Go to your cPanel account and click to file manager.
- Once the file manager loads, click Settings.
- Make sure that Show Hidden Files (dotfiles) is checked, and click Save.
- Once you select the specific domain to be redirected (shown in the picture that is Document root), close the window and again click file manager from your cPanel.Click on public_html, and open your .htaccess if you already have one. If not, click File+, name the file .htaccess and click Create New File.
- Select the .htaccess file, and click Edit.
- If you just created your .htaccess file, use the following code to set up the URL redirect to the HTTPS version of your website:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Automatically Redirect Your WordPress Website’s Traffic from HTTP to HTTPS in Apache
- Login to your Apache server and go to the path where it’s installed.
- Go to the conf folder and take a backup of httpd.conf file
- Open httpd.conf using your favorite editor
- Ensure mod_rewrite.so module is loaded
- If you see LoadModule rewrite_module modules/mod_rewrite.so this line is commented then uncomment it
- Add the following at the end of the file
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
7. Restart Apache web server to test it.
Automatically Redirect Your WordPress Website’s Traffic from HTTP to HTTPS in Nginx
- Login to Nginx web server and take a backup of nginx.conf or default.conf file (whatever file you are using for server directive)
- Add the following in server directive
server {
listen 80;
server_name domain.com www.domain.com;
return 301 https://domain.com$request_uri;
} - Save the file and restart Nginx web server
- Restart Nginx to test the site.
Automatically Redirect Website’s Traffic from HTTP to HTTPS in CloudFlare
If you are leveraging CloudFlare for performance and security then having a website through HTTPS is very easy. Cloud Flare provides free SSL cert, and you can do a redirection through page rules. The steps are given below:
- Log in to Cloud Flare and select the site
- Go to Page Rules
- Click “Create Page Rule”
- Enter the URL (put the asterisk, so redirection happens for all the URI)
- Click “Add a Setting” and select “Always Use HTTPS” from the drop-down
- Click “Save and Deploy”
It will take a few seconds, and you are all set to have your website accessible through HTTPS.