1

When I type example.com in the URL it first redirects to http://example.com then to https://example.com and finally to the https://www.example.com (the original address).

Why doesn't it straight away redirect http://example.com to https://www.example.com? Otherwise the direct traffic of my website has to go through one extra redirection causing slow load time.

1
  • 1
    There's nothing actually wrong with the chained redirect you are seeing (providing this is done early in .htaccess - this should not cause a "slow load time") - in fact, this double redirect (1st to HTTPS on the same host) is actually a requirement if you plan on implementing HSTS in the future. These should also be 301 redirects, so the browser will cache them. Aside: "it first redirects to http://example.com" - that's not a "redirect", it's simply the initial request (but I guess from your later text that you already know that.) – MrWhite Nov 19 '19 at 11:13
1

Check your .htaccess for the redirections. I suppose it is an internal redirection made by WordPress.

You can try this in the .htaccess.

Make sure to have mod_rewrite activated in your server.

RewriteEngine On

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

1
  • 1
    You need to include the OR flag on the first condition, otherwise it's not going to redirect http://www.example.com to HTTPS. Also, don't forget to escape literal dots in the regex and the QSA flag is not required here. – MrWhite Nov 19 '19 at 10:58

Your Answer

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