Search code examples
.htaccessdnssubdomainplesk

Redirect subdomain to another domain with dns or htaccess


I'd like to redirect subdomain.domain1.example to domain2.example without changing the URL of subdomain.

Example:

subdomain.domain1.example = domain2.example

subdomain.domain1.example/connexion = domain2.example/connexion

Is it possible with DNS or htaccess redirection (not 301 or 302) ?

It's the same website with 2 URLs. By the way, I'm using Plesk to handle my server.

I know it appears like duplicate content to Google, but I don't care.

PS1: I can use rsync, but it's not really good solution

PS2: I tried symbolic link but Plesk doesn't like that


Solution

  • It's the same website with 2 urls. ... I kwnow it appears like duplicate content to google"

    So in that case it's not a "redirect" that you want - as that will change the hostname to domain2.example.

    One way would be to:

    1. Set a DNS A record for subdomain.domain1.example that points to the IP address of domain2.example.
    2. In the <VirtualHost> container of domain2.example configure a ServerAlias so that the server will accept requests to subdomain.domain1.example. For example:

      ServerAlias subdomain.domain1.example