0
votes

I'm not sure if this even is possible to do, but I have two different domains on two different webservers. Both have a SSL-certificate. What I need is for all links on domain1 (both http and https) to be redirected to domain2 with https. Example:

http://domain1.com/customlink should be redirected to https://domain2.com/customlink

Also https://domain1.com/customlink should be redirected to the same as above.

Is this possible to achieve by having a .htaccess file with some rules on the webserver of domain1.com? It is important that whatever the user writes after domain1.com, also will be kept in the new redirected link.

1
This sounds like a relatively standard domain redirect? Is there a specific problem you are having? - MrWhite
It might seem so, my host told me that you cannot redirect "example.com/SOMETHING" and keep the part after slash onto the new domain, but I guess that was a lie. - BTB

1 Answers

1
votes

I'm not sure if this even is possible to do .... my host told me that you cannot redirect https://example.com/SOMETHING and keep the part after slash onto the new domain

I feel there must be something more to this question, as otherwise, this is just a standard domain redirect...

  • two different domains on two different webservers
  • Both have a SSL-certificate.
  • Assuming there is only 1 domain (ie. domain1.com) hosted on the first server that you want to redirect.

Then, in your .htaccess file at domain1.com, use a mod_alias Redirect:

Redirect 302 / https://domain2.com/

You should remove all other directives in the .htaccess file at domain1.com in order to avoid potential conflicts (they aren't being used anyway, since you are redirecting everything).

The mod_alias Redirect directive is prefix-matching, and everything after the match is passed on to the target. eg. /foo/bar/baz is redirected to https://domain2.com/foo/bar/baz. Everything (HTTP and HTTPS) is redirected to domain2.com (HTTPS).

This is currently a 302 (temporary) redirect. Only change to a 301 (permanent) - if that is the intention - once you have confirmed this works as intended. This is to avoid any potential caching issues.