How to make redirects in Apache2 in Ubuntu 16.04?

0

I have the domains mycompany.com & mycompany.com.co

Goal : I want all traffic to go only to www.mycompany.com

Doubts :

  • In which file should the redirect be located in the Virtualhost directly or in an .htaccess file?

  • If it is in the Virtualhost, I use the Myhost.com virtualhost and treat the variables of my main domain like mycompany.com.co www.mycompany.com.co like ServerAlias?

  • Or for each variation of my domain to which I want to direct traffic I must create your own Virtualhost axis: to address the traffic of mycompany.com.co mycompany.com mycompany.org I create a Virtualhost for everyone and I do 301 redirects directing the traffic to www.mycompany.com

  • asked by Cristian Camilo Flórez 08.04.2018 в 12:52
    source

    1 answer

    1

    A quick way without having to create them completely is with a permanent redirect from a virtualhost .

    I completely mean not creating directories and .htaccess . This way you would have them all in the directory where apache saves the activated sites.

    <VirtualHost *:80>
      ServerName miempresa.com.co
      ServerAlias www.miempresa.com.co
      Redirect 301 / http://www.miempresa.com/
    </VirtualHost>
    
    <VirtualHost *:80>
      ServerName miempresa.org
      ServerAlias www.miempresa.org
      Redirect 301 / http://www.miempresa.com/
    </VirtualHost>
    
      

    Additional if other users need it:
      In this answer there is information on how to create and activate the virtualhost .

    EDIT and add

    For variations that are not from the domain my empresa.com , be the three www or any other subdomain subdomain.miempresa.org you use ServerAlias separating each variation for a space:

    <VirtualHost *:80>
      ServerName miempresa.org
      ServerAlias www.miempresa.org subdomain.miempresa.org
      Redirect 301 / http://www.miempresa.com/
    </VirtualHost>
    

    For the main domain, you can do it from htaccess or from the server control panel, if you allow it.

    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.miempresa\.com$
    RewriteRule (.*) http://www.miempresa.com/$1 [L,R=301]
    
        
    answered by 08.04.2018 в 20:58