Multiple TLD -.htaccess 301 Redirects

I have a Ubuntu server that runs Apache w / Virtual Hosts. I run a website with a primary domain like "mydomain.com" and it is located at /var/www/mydomain.com.

Assuming I have multiple domain names (each with a different tld), the best way to make sure that they all point to "mydomain.com" (the main site).

In other words, is it better to create a .htaccess file in / var / www that has several 301 redirects for sites like "mydomain.net" and "mydomain.org" that point to "mydomain.com"?

+4
source share
1 answer

Try something like this:

<VirtualHost 1.2.3.4:80> DocumentRoot /var/www/mydomain.com ServerName mydomain.org ServerAlias mydomain.net mydomain.info mydomain.me RedirectPermanent / http://www.mydomain.com/ </VirtualHost> 
+5
source

All Articles