How to force a website to redirect from http to https using htaccess

Here am going to explain you how force a website redirect from http to https using htaccess files, we all know htaccess is the configuration files normally using in Apache web server to specify redirect rules.we can write our own URL redirect rules and based on we can change the entire website url structure.

Most common use of URL redirects for SEO purpose and better page readability/simplicity, we have lots of rule for redirecting here am going to explain you reule to redirect from http to https using htaccess files

See below force a website redirect from http to https using htaccess
This is full .htaccess to files redirect from http to https

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

Step 1

First you have to activate RewriteEngine

RewriteEngine On

Step 2

Check if the browser is requesting by http

RewriteCond %{HTTP_HOST} ^(www\.)?tutorialshore\.com

Step 3

if the browser is requesting by http then force to redirect to https

RewriteRule ^(.*)$ https://www.tutorialshore.com/$1 [R,L]


How to force website redirect from http to https using htaccess

Or we can use below code


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

See All answers

My Thought

Your email address will not be published. Required fields are marked *

Our Tool : hike percentage calculator