0

I have a Wordpress site which was migrated with some matters. The goal is force to redirect always with https and www.

That works EXCEPT for http://www.caravelleconsulting.com which redirects to http://www.caravelleconsulting.com without https

.htaccess

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

#Redirection to HTTPS AND WWW
# version 1
#RewriteCond %{HTTP_HOST} ^caravelleconsulting\.com$
#RewriteRule ^(.*)$ "https\:\/\/www\.caravelleconsulting\.com\/$1" [R=301,L]
# Version 2 - same result than the first version
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]


# send to router
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

</IfModule>

# END WordPress

I found a third solution here but when I test with http://www.redirect-checker.org, I got a 301 Moved Permanently loop.

How can I resolve this ?

J.BizMai
  • 2,621
  • 3
  • 25
  • 49

1 Answers1

0

Finally, I found my solution based on several answers here

.htaccess

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

#First rewrite any request to the wrong domain to use the correct one (here www.)
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#Now, rewrite to HTTPS:
#avoid loop - (https://stackoverflow.com/questions/13977851/htaccess-redirect-to-https-www)
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


# send to router
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

</IfModule>

# END WordPress
J.BizMai
  • 2,621
  • 3
  • 25
  • 49