Home How to How to Force HTTP traffic to HTTPS using .htaccess file

How to Force HTTP traffic to HTTPS using .htaccess file

by Wikky
2 comments
force-http-to-https

The code Below is to Force all traffic of your website from HTTP request to HTTPS using .htaccess file once you have configured your SSL. Open your .htaccess file located on root of your web directory. If not shown in the files then change setting to view hidden files in web directories (shown image below).

how-to-show-hidden-files in-cpanel files-manager
show-hidden-files in-cpanel files-manager

Add following lines to your .htaccess file under <IfModule mod_rewrite.c> tag.

RewriteCond %{REQUEST_URI} !^/[0-9]+..+.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/.well-known/pki-validation/[A-F0-9]{32}.txt(?:\ Comodo\ DCV)?$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Now check your website by entering http://domain.com, you will see your website is redirected to https:// protocol.

Hope this help!


Posts you may like:


    You may also like

    2 comments

    Zachery July 1, 2021 - 7:02 am

    Yes! Finally something about website.

    Reply
    Cameron July 6, 2021 - 7:58 pm

    Excellent way of telling, and fastidious piece of writing to take information about my presentation subject matter, which i am going
    to deliver in college.

    Reply

    Leave a Comment

    This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More