2

my webpage is duplicated because of the SSL certificate (http:// example.com and https:// example.com). I want to redirect from http to https. But I have two questions:

If my webpage has several pages (Home, About, Contact...), should I make a redirect for each page? Or just with the http:// example.com and then the rest of its pages will redirect correctly?

I consulted in several websites and forums and I get two different codes from them for the .htaccess file:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://example.com%{REQUEST_URI} [L,R=301]

And there is the other one:

<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} off
RewriteRule (.*) https://www.example.com/$1 [R=301,L,QSA]
</IfModule>

Which one is the correct one or the best one for redirecting from HTTP to HTTPS?

3

If my webpage has several pages (Home, About, Contact...), should I make a redirect for each page? Or just with the http:// example.com and then the rest of its pages will redirect correctly?

Neither. What you want to do is redirect any http request to https for any URL. Both of the .htaccess directives you posted above will do that.

Which one is the correct one or the best one for redirecting from HTTP to HTTPS?

They are both correct, up to a point. Both snippets assume Apache is the web server. The first snippet assumes mod_rewrite is present, the second checks it first but either one should work. The only other significant difference is that the second one calls the QSA flag which preserves any query strings on the rewrite. You may or may not need that.

Also, both snippets call the L (Last) flag which indicates this is the last rewrite. If you are performing additional rewrites after this one, remove the L flag.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.