I have example.com and example.co.uk. They both point to the same Drupal installation on my server, so both domains load the exact same site.
I am now trying to redirect the .co.uk to the .com domain. I have tried using the following lines in the .htaccess file, but it always redirects to /index.php.
RewriteCond %{HTTP_HOST} ^example.co.uk
RewriteRule ^(.*) https://example.com/$1 [P]
The following lines didn't work either.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.co.uk$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
The site redirects. but it doesn't keep the URL structure as it should. If I go to example.co.uk, I get redirected to example.com. If I go to example.co.uk/node/1, I get redirect to example.com/index.
How can I set up the correct redirect?