Redirecting multiple top-level domains (TLDs) to one TLD, without www, using .htaccess
Aug 25, 2017 · 1 min read
Let’s say you have multiple top-level domains registered for a business (mybusiness.com, mybusiness.net, mybusiness.org, mybusiness.info) and you what to redirect traffic from all them to one domain (mybusiness.com), and without www.
This is how you do it using .htaccess.
Prerequisites
For this to work you need three things first:
- All those domains must have their DNS records properly configured to point to the same location.
- An Apache web server (hence
.htaccess) has to be installed on the end point of the domains and the web server needs to be configured to point all the domains to the same location. - Apache
mod_rewritemodule must be enabled.
Solution
Voila…
The above code translates into:
If the HTTP_HOST (starts with or not with www and ends in .net or .org or .info) or (starts with www and ends with .com),
Then redirect all traffic to .com domain host, retaining the rest of the URL used.
