Home > Mobile >  Not redirecting properly the https when changing domain
Not redirecting properly the https when changing domain

Time:03-02

I have two domains loaded in my Plesk websites and domains section, the two domains are without www, so let´s say the two domains are:

example.com
example.es

When I redirect from example.es to example.com it is done but with http, not with https.

So, I decided to edit my .htaccess file with the follwing instructions:

RewriteEngine On    
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}

But my page is not loaded properly, because seeing the web inspector it creates an infinite loop of requests to my main page example.com.

Anyone knows some kind of solutions?

CodePudding user response:

And I have Application Load Balancer for the ssl certificate that is inside my EC2 AWS machines.

Try the following instead:

RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{HTTP:X-Forwarded-Proto} ^http$
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

The connection between the load balancer and your application server is likely HTTP only, so the HTTPS Apache server variable is always off.

(Test first with a 302 - temporary - redirect to avoid potential caching issues.)

Although if you are redirecting everything (ie. example.es) to example.com then do something like the following instead:

RewriteCond %{HTTP_HOST} !=example.com [NC,OR]
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L]

Assuming both domains point to the same document root then you don't need your redirect in Plesk, which will otherwise result in 2 redirects by the sound of it.

  • Related