How to redirect from HTTP to HTTPS using a .htaccess file?

Collapse

Unconfigured Ad Widget

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Ryaan J.
    Senior Member
    • Apr 2022
    • 103

    How to redirect from HTTP to HTTPS using a .htaccess file?

    Hello,

    I have installed SSL on my domain and want to redirect website traffic from http to https. Can anyone please assist me with how to redirect the website to HTTPS via the .htaccess file?
  • Rex Maughan
    Senior Member
    • Mar 2022
    • 112

    #2

    Hello Ryaan J.,


    If you have installed an SSL Certificate on your website and want to redirect your website traffic from http to https using the .htaccess file, you can follow the below steps,

    You'll need to add the following code to your .htaccess file for the redirection.
    • Firstly, If you're looking to redirect a specific domain from HTTP to HTTPS, then add the following line to your .htaccess,
    Code:
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^example\.com [NC]
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://[URL="http://www.example.com/"]www.example.com[/URL]/$1 [R,L]
    • Now, If you're looking to redirect a specific folder from HTTP to HTTPS, then add the following line to your .htaccess,
    Code:
    RewriteEngine On
    RewriteCond %{SERVER_PORT} 80
    RewriteCond %{REQUEST_URI} folder
    RewriteRule ^(.*)$ https://www.example.com/folder/$1 [R,L]
    • Lastly, If you're looking to redirect All Web Traffic from HTTP to HTTPS, then add the following line to your .htaccess,
    Code:
    RewriteEngine On
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]
    Note: You'll need to replace example.com with your domain name wherever required in the code and set the folder name wherever required.

    Thus, I hope the ways mentioned above help you to redirect from HTTP to HTTPS using a .htaccess file without facing any issues.

    -----------------------------
    Regards,
    Rex Maughan

    Comment

    Working...
    X