Redirecting from http to https through .htaccess
I am trying to do a 301 redirect. I am using letsencrypt SSL certificate here, so my redirect will be from http to https. My query is that my script provider (Mybb) has provided me with one code and letsencrypt has provided with another.
Mybb has provided me this one:
Letsencrypt has provided this one:
And here in cPanel I have been suggested this one:
I want to know what's difference between these. Are their function any different or all the same? I am confused because mybb has already provided a default .htaccess file in which there are codes similar to these (which I have to assume those are their default redirects). So, which code to use?
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Letsencrypt has provided this one:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://mysitename.com/$1 [R=301,L]
And here in cPanel I have been suggested this one:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I want to know what's difference between these. Are their function any different or all the same? I am confused because mybb has already provided a default .htaccess file in which there are codes similar to these (which I have to assume those are their default redirects). So, which code to use?
-
Hello @Mrinmoy What would be best to understand what each rule is doing is to read the Apache documentation on rewrite rules and conditions: Apache mod_rewrite Introduction - Apache HTTP Server Version 2.4 0 -
MyBB: redirect if not https protocol Letsencrypt: redirect if default http port (=80, SSL/HTTPS is 403) CPanel: same as MyBB 0 -
I used the third code which was provided by cPanel. And it worked like a charm. Thanks. 0
Please sign in to leave a comment.
Comments
4 comments