0

I am using apache2 in Ubuntu 14 and have set up multiple conf files for multiple domains. However, when I am trying to add a new domain with a similar conf file it's not working. The conf file for the new domain looks like:

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        ServerName www.rampatra.com
        #ServerAlias www.rampatra.com

        ServerAdmin webmaster@rampatra.com
        DocumentRoot /var/www/rampatra.com

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
        RewriteEngine on
        RewriteCond %{SERVER_NAME} =www.rampatra.com
        RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

# WWW Redirect
<VirtualHost *:80>
        ServerName rampatra.com
        Redirect permanent / http://www.rampatra.com/
        RewriteEngine on
        RewriteCond %{SERVER_NAME} =rampatra.com
        RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

The problem I am having is that when I visit rampatra.com it redirects me to another domain, however, I have the exact same conf file for ramswaroop.me and it works fine. Can you guys please tell me what am I missing here?

Ram Patra
  • 111
  • 4

1 Answers1

0

Adding two conf files solved the issue. One rampatra.com.conf and the other rampatra.com-le-ssl.conf. I needed the second conf file as I am using ssl certificates from let's encrypt.

Also, don't forget to enable the site by:

sudo a2ensite rampatra.com.conf
sudo a2ensite rampatra.com-le-ssl.conf

And then finally, restart apache2 server by:

sudo service apache2 restart
Ram Patra
  • 111
  • 4