HTTP to HTTPS Redirect

Once you have installed an SSL certificate on your website, you need to Redirect HTTP to HTTPS. If you don’t redirect HTTP to HTTPS, Your website visitor can’t access your website through SSL(HTTPS) and your website will accessible via a regular insecure HTTP connection. Without HTTPS redirection Chrome and Firefox will show insecure warnings on your sites. Without an SSL certificate, your website will show insecure to the visitors. If you do not install an SSL certificate yet on your website, Get your website SSL certificate now for free. Follow this tutorial:

How to install a free SSL certificate on your website using Let’s Encrypt

To access your website securely with https, Your website visitor must enter your website URL with https in their browser address bar. If you want that your visitor will automatically access secure https connection, It’s very important to redirect HTTP to HTTPS. After redirection, if anyone visits your website entering URL like “http://yourwebsite.com” or “yourwebsite.com” they will be automatically redirected to “https://yourwebsite.com” or “https://www.yourwebsite.com”. Their connection will be secured & encrypted by your website SSL certificate.

redirect http to https

In this article, I will show you how to redirect HTTP to HTTPS. Before redirecting HTTP to HTTPS, Please make sure your website SSL certificate working or not. So, Let’s start

 

WordPress redirect HTTP to HTTPS 

If you are using WordPress CMS, You can easily redirect HTTP to HTTPS by installing a Really Simple SSL plugin on your website. Just go to your WordPress dashboard plugin section. Then click ADD NEW button and search Really Simple SSL plugin. The plugin has 3 million+active installs with an average 5-star rating. You just click on install and click on “Go ahead, activate SSL”. It will automatically redirect your website HTTP to HTTPS. It’s very easy to redirect from HTTP to HTTPS on your WordPress website. Currently, I am using this really simple SSL plugin to redirect HTTP to HTTPS on our website.

HTTP to HTTPS redirect

 

WHAT DOES THE PLUGIN ACTUALLY DO?

  • All incoming requests are redirected from HTTP to HTTPS. Default with php and javascript redirect or else with the .htaccess redirect.
  • The WordPress site URL and home URL are changed to https.
  • Your insecure content is fixed by replacing all HTTP:// URLs with HTTPS://, except links to other external domains. Everything is done dynamically. Other than the WordPress site URL and home URL, no other database changes are made.

Also, You can use other WordPress plugins like WP Force SSL, One-Click SSL, Easy HTTPS Redirection (SSL) to redirect HTTP to HTTPS.

Redirect HTTP to HTTPS In Apache

Editing .htaccess in cPanel File Manager

You need to create a .htaccess file or edit existing .htaccess file for the redirect HTTP to HTTPS, and you can use your control panel’s File Manager to edit .htaccess file.

  • Login to your website Cpanel
  • Click on file manager from the file sectionCpanel File Manager
  • Go to your website root directory from the file manager. The default root directory is public_html.
  • Find the .htaccess file. If you can’t find .htaccess file, Click on settings & Check “Show Hidden Files (dotfiles)”. Also, If you can’t find it, create a new .htaccess file in the root directory.find htaccess file
  • Right-click on the .htaccess file and click on “Code Edit” on the menu.
  • A dialogue box may pop up asking about encoding. Click the “Edit” button to continue.
  • Edit the file & add the following HTTP to HTTPS redirection code. Don’t remove the existing code in .htaccess file. Do not duplicate RewriteEngine On.
  • click on ”Save Changes” when editing is done.
  • Test your website to make sure it is working correctly. If any error appears, restore to the previous version by pressing “CTRL+Z” on the keyboard.
  • Once you are done, click “Close” to close the editing.

Redirect All Website Traffic to HTTPS

To automatically redirect all web traffic from HTTP to HTTPS add the following code in the .htaccess file:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Redirect Only a Specific Domain

If you want to redirect a specific domain to use HTTPS, add the following code in htaccess file:

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^yourdomain\.com [NC] 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.webcods.com/$1 [R,L]

Note: Please replace “webcods.com” with your domain name. 

Redirect Only a Specific Directory

Redirecting to HTTPS on a specific folder, add the following:

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} directory 
RewriteRule ^(.*)$ https://www.webcods.com/directory/$1 [R,L]

Note: Please replace “webcods.com” with your domain name and replace /directory with the actual directory name.

Redirect HTTP to HTTPS in NGINX

if you have too many websites hosted on the server and you want to use HTTPS for all website, You don’t need to create a separate HTTP server block for each site you can create a single configuration file to redirect all HTTP sites.

Add the following code in Nginx configuration file to redirect all of your websites visitor to HTTPS:

server {
	listen 80 default_server;
	listen [::]:80 default_server;
	server_name _;
	return 301 https://$host$request_uri;
}

An example, if the visitor enter http://yourwebsite.com/page1 in the browser, Nginx will redirect the request to https://yourwebsite.com/page1.

To redirect a single website to HTTPS to HTTPS open domain Nginx configuration file and add the following code:

server {
    listen 80;
    listen [::]:80;
    server_name webcods.com www.webcods.com;
    return 301 https://webcods.com$request_uri;
}
server {
    listen 80;
    listen [::]:80;
    server_name webcods.com www.webcods.com;
    return 301 https://webcods.com$request_uri;
}

server {
    listen 443 ssl http2;
    server_name www.webcods.com;

    # . . . other code

    return 301 https://webcods.com$request_uri;
}

server {
    listen 443 ssl http2;
    server_name webcods.com;

    # . . . other code
}

Once you have installed an SSL certificate on your website, you should redirect HTTP  to HTTPS. I hope this article will help you to redirect HTTP to HTTPS. If you need any help to install an SSL certificate and redirect HTTP to HTTPS, click here to contact me.

LEAVE A REPLY

Please enter your comment!
Please enter your name here