SSL redirection of website

You need to Install SSL certificate to force htaccess redirect to HTTPS.

1.Login to your web hosting control panel

2.Go to public folder and find .htaccess file

3. Edit the .htaccess file and add the following code to redirect to https

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

Please replace yourdomain.com with your actual domain.

Redirect to https and non-www use code below

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

Redirect to https and www use code below

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(.*)$  [NC]
RewriteRule (.*) https://www.%1/$1 [R=301,L]
Was this article helpful?
YesNo

Leave a Reply

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