I believe this can be done by changing IP of another.example
to example.com
and adding some codes in the .htaccess
file.
You certainly should not be "changing the IP" of any domain. (What was your reasoning behind this?)
This sounds like a relatively simply redirect that can be performed in the .htaccess
file. A condition is required that checks for the specific subdomain.
I assume all your "virtual" subdomains of example.com
point to the document root of example.com
. In which case you would put something like the following (using mod_rewrite) near the top of the .htaccess
file in the root of example.com
:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^abc\.example\.com [NC]
RewriteRule ^ https://another.example%{REQUEST_URI} [R=302,L]
The RewriteCond
(condition) checks for the specific subdomain/hostname (note that this is a regex). The REQUEST_URI
server variable contains the requested URL-path, which is appended onto the end of the target domain.
Note that this is a temporary (302) redirect. Only change this to a permanent (301) redirect - if that is the intention - once you have tested this is working OK. 301s are cached persistently by the browser so can make testing problematic.
another.example
- or could the target domain vary? Do your subdomains point to a common root directory atexample.com
? – MrWhite Nov 11 at 12:39