Apache .htaccess domain TLD redirect

For when I forget, because I rarely use Apache any longer:

Create a .htaccess file in the document root for the site, adjusting the source domain (in this case subdomain.exmaple.co.uk) and the destination domain (subdomain.example.com):

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{HTTP_HOST} ^subdomain.example.co.uk$
  RewriteRule (.*)$ https://subdomain.example.com/$1 [R=302,L]
</IfModule>

Leave a Reply