HTTP to HTTPS redirection using .htaccess file | SEO Booster

Search Engine Optimization / WordPress Hacks

HTTP to HTTPS redirection using .htaccess file | SEO Booster

SSL check is always mandatory for website SEO and to get good remarks from Google. Without an SSL you can’t perform HTTP to HTTPS redirection. I have always suggested people to use SSL. Now the question is why HTTPS redirection is so important?

Does HTTPS redirection help in website SEO? What will be the effect on my website if I don’t use HTTPS? So, let’s see the importance of HTTP to HTTPS redirection.

Read Also: How to create a WordPress website step by step?

Why HTTPS to HTTPS redirection is important today?

You know it happens with everybody when you visit a website, It says “This site doesn’t have a secure connection.” And it sucks. They have put a lot of efforts to write and deliver a good content. But their site is not secure due to invalid SSL.

Browsers like Chrome and Mozilla will show and recommend not to visit that site. Giving some security reasons.

Example Case Study while doing SEO

A travel business came to me for SEO on his website. They started complaining that we are not getting any leads from our ads campaign. They were actually running a Google AdWords campaign for getting some calls and signups. But they don’t have HTTPS on their website.

This is what we call foolishness. His half of AdWords campaign money will be lost due to the browser not to visit recommendation. So, generating sales and leads by that campaign is far away.

You know in this particular case HTTP to HTTPS redirection is not only the factor that affected the lead. There were a lot of other factors as well. Which I will discuss some other time.

So, the first thing I recommended them to install an SSL certificate. Namecheap is providing very cheap and good SSL Certificates. You can take from there.

Things to do before doing HTTP to HTTPS redirection

You know, you can’t perform a HTTPS redirection without having a valid SSL. So, you have to install SSL first if you want to do HTTPS redirection.

If you don’t know how to install an SSL certificate. You can refer the below article. It will provide a good knowledge base for every server. You can choose accordingly like in my case it is cPanel.

Recommended ReadHow to install SSL certificate?

HTTP to HTTPS redirection using .htaccess file

In most of the cases, when you have domain, hosting and SSL from the same provider. You need need to perform HTTPS redirection. But, in cases it is required to do it manually.

So, this can be done easily by the .htaccess file. You can find this file in your root directory.

Ways to edit an .htaccess file:

  1. Use a text editor and SSH to edit the file.
  2. Use the File Manager in cPanel to edit the file.
  3. Edit the file on your computer using notepad or notepad++ and upload it to the server using FTP.
  4. Use the “Edit” mode in the FTP program that allows you to edit a file remotely.

In my recommendation, the better way to do it is to “use the file manager in cPanel.”

Filem Manager in Cpanel Okey ravi SEO
File Manager In cPanel

Pro Tip: Always take a backup of your whole site, before editing .htaccess file. A single mistake will destroy your site sometimes.

Editing .htaccess in cPanel File Manager

  1. Login to cPanel, use domainname.com/cpanel
  2. Open File Manager
  3. Check “Show Hidden Files (dotfiles)” in case if you don’t find the .htaccess file. In the case of multi-hosting, you have to go to the relevant website folder
  4. Click “Go”
  5. After a new tab or window opens, look for the .htaccess file
  6. Right click on the .htaccess file and click on “Edit” on the menu (refer the below image)
  7. A dialogue box may pop up asking about encoding. Click “Edit” button to continue
  8. Edit the file accordingly the codes suggested below
  9. Click on “Save Changes” when done
  10. Test your website to make sure it is done correctly. In case, there is an error, restore to the previous version and try again
  11. You can now close or logout if you don’t need
Editing the .htaccess file

Redirecting HTTP to HTTPS using .htaccess

1. Redirecting All Web Traffic

If you want to redirect all your website traffic to HTTPS then add the following code into your .htaccess file. You can enter these codes between  # BEGIN WordPress and # END WordPress. Like this –

Redirection for HTTPS and WWW both

# BEGIN WordPress
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https:
//www.yourdomain.com/$1 [R,L]
# END WordPress

Redirection for only HTTPS

# BEGIN WordPress
RewriteEngine On
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https:
//yourdomain.com/$1 [R,L]
# END WordPress

editing .htaccess file in Cpanel http to https redirection okey ravi SEO
.htaccess code sample

Note: Replace “yourdomain.com” with your original domain name. 

2. Redirecting a specific domain only

For redirecting a specific domain to use HTTPS, add the following code.

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

Note: Here also you need to replace “yourdomian.com” with your original domain name.

3. Redirecting a specific folder only

For redirecting to HTTPS on a specific folder, add the following code. By the way this is not required most of the time.

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

Note: Replace “yourdomain” with your original domain name wherever required. Also, in case of the folder, replace /folder with the actual folder name.

If you liked this article, then please subscribe to our YouTube Channel for WordPress, SEO, Affiliate marketing and AdSense video tutorials. You can also find us on Twitter and join our Digital marketing hacks Facebook group.

If you have nay query or suggestions, feel free to comment below.

Read Next: How to edit an ads.txt file? 

Comments are closed.