Categories: SecuritySSL

How to redirect a site to https using htaccess

If you want to redirect your domain from HTTP to HTTPS, you can achieve this using

 

If you are not using Cloudflare or any proxy server, use the below code in your .htaccess file

RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS} =off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

If you are using Cloudflare or any proxy server, use the below code in your .htaccess file
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

 

If you  are on WordPress, you will need to install the Cloudflare  SSL plugin before activating the files in .htaccess file.

One of the plugins is https://wordpress.org/plugins/cloudflare-flexible-ssl/

Hosting Ahead

Recent Posts

Run composer with different PHP version

If multiple PHP versions are installed on your server you need to tell the composer…

2 years ago

How to Install WordPress using WordPress Toolkit in cPanel

Wordpress toolkit allows the installation, configuration, and management of Wordpress. The first step is to…

3 years ago

Configure OpenVPN Client Devices for Andriod

These instructions cover installing and configuring the OpenVPN Connect app  Client-Side Configurations: Android There are…

3 years ago

The certificate chain was issued by an authority that is not trusted | SQL Server

This error may appear when you try to connect to Microsft SQL server or you…

4 years ago

Free website hosting support in this COVID pandemic

Hello everyone, The COVID-19 should have affected almost everyone in a way or another. When…

4 years ago

Amazon workspaces to build a secure work from home cloud infrastructure

Based on the current Covid19 scenario, several companies asked employees to work from home. Google…

4 years ago