0

Have a small wordpress blog and was following this guide. One of the step was to change htaccess file for redirects for non-www and www to https www. According to https://varvy.com/tools/redirects/ there should only be one redirect on each type.

But for my no www no http to https www there is 2 redirect happening.

http://myportal.com 301 redirect https://myportal.com/

https://myportal.com/ 301 redirect https://www.myportal.com/

Many of the tools are taking this as a negative and saying too many redirects. How can I make the 2 step into 1 step? So the result comes to

http://myportal.com 301 redirect https://www.myportal.com/

Currently have the following code.

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Chris T
  • 155
  • 1
  • 11

1 Answers1

0

You can use the following rule to force https and www in a single URL redirection.

RewriteEngine on

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^(.*)$ https://www.%1%{REQUEST_URI} [L,R=301]

Note : Remove the non-www to to www redirect rule If you already have that rule in your htaccess otherwise that might conflict with this one. Make sure to clear your browser cache before testing this new rule.

Amit Verma
  • 40,709
  • 21
  • 93
  • 115
  • 1
    thanks.. I had tried this from an answer to another question but for some reason that had gone into a loop. But seems to be working now. Thanks – Chris T May 08 '19 at 03:18
  • Sir can you please help me on [this post](https://stackoverflow.com/questions/56023527/mod-rewrite-query-parameter-validation-and-blocking-also-request-url-blocking) – user3637224 May 08 '19 at 06:32