I hold my website on google cloud with one-click deploy wordpress. GNU/Linux system, Apache. I want to redirect https://example.com to https://www.example.com. So I update the .htaccess file as the tutorial from stack overflow. It comes the error "ERR_TOO_MANY_REDIRECTS". I was wondering if there are some redirect rules existed already because when I visit https://www.example.com, it automatically go to https://example.com.
I've tried a lot of rules
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301]
and
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?!www\.)(.+) [NC]
RewriteRule ^(.*) http://www.%1/$1 [R=301,NE,L]
How can I troubleshoot? Thank you very much