0

I have tried a zillion variations of .htaccess rewrites and cannot get this to work.

I have a previous HTTPS old-domain.com that I need to forward to new-domain.io. Both are HTTPS but only the new domain has SSL certs on the server. This makes the browser trying to load old-domain.com just spin in the browser.

I already have a DNS forward that works fine ONLY with http, not https. I am thinking that I need to use something like %{HTTP:X-Forwarded-Proto} but not exactly sure how. Nothing has worked so far.

https://old-domain.com AND https://www.old-domain.com

both need to redirect to https://new-domain.io (along with any URI like/something/this.html)

Something like this looks like it should work, but redirects infinitely.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^old-domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.old-domain\.com$
RewriteRule (.*)$ https://new-domain.io/$1 [R=301,L]

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*)$ https://new-domain.io/$1 [R=301,L]

SOLUTION -------- The new domain .htaccess file cannot fix a HTTPS redirected link by itself. There are two ways to correctly fix it.

  1. Remove DNS forwarding at the old domain DNS. Then make sure there are still valid SSL certs AND put a redirect on its .htaccess file to handle the redirects with something like this:

    RewriteEngine On

    RewriteCond %{HTTP_HOST} (w*)domain.com$ [NC] RewriteRule ^ http://newdomain.com%{REQUEST_URI} [L,R=301]

  2. Leave the DNS forwarding of the old domain and add a new multi-domain SSL cert at the new domain which includes BOTH domains. This is tricky because you will have to manually authenticate the old domain because the cert won't be living at the old domain host.

I choose and implemented #1 successfully.

B-Money
  • 1,040
  • 10
  • 12
  • i flagged your question as duplicate. Look into the solution under https://stackoverflow.com/a/26623196/1992004 – Evgeniy Dec 10 '18 at 15:39
  • Thanks but no this didn't solve my problem. I think it's due to the SSL domain looks for the certs BEFORE loading anything from the server, like .htaccess. Therefore I cannot affect the old domain HTTPS traffic without valid certs for the old domain. – B-Money Dec 10 '18 at 19:36
  • 2
    And that last comment is your answer. SSL negotiation is done *before* anything else is done. So if your SSL certificate is bad, you are out of luck. If you own both domains, you could setup your certificate on the new-domain to cover both the old and the new domain names (see alt-names). This way, whichever name apache gets, the certificate will be valid, then it will work. The name resolution for both the old and the new should point to the IP of the new server. – Nic3500 Dec 11 '18 at 05:26

0 Answers0