There are many ways to do this. I just give you the most straightforward (of course for me!) and simplest one.
In hook_preprocess_html
use this code
THEME_preprocess_html(&$var){
$host = $_SERVER['HTTP_HOST']. request_uri();
if(strpos($_SERVER['HTTP_HOST'],'example2') !=false)
header("location:example.com/".request_uri());
}
I can't test this code right now, but this is the main idea:
Get current url components separately, the host ($_SERVER['HTTP_HOST']
) and what comes after it (request_uri()
), if its $_SERVER['HTTP_HOST']
contains example2
as a substring, then redirect the user to example.com/request_uri()
For redirection you can also use drupal_goto
or anything else you want I just gave you the pure PHP.