Redirecting multiple top-level domains (TLDs) to one TLD, without www, using .htaccess

Horatiu Cristea
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:

  1. All those domains must have their DNS records properly configured to point to the same location.
  2. 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.
  3. Apache mod_rewrite module must be enabled.

Solution

Voila…

Redirect multiple top-level domains to the .com domain without www

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.

)
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade