0

I have two different sites
domain1.com
domain2.com

Problem : I only can access domain2.com by using www.domain2.com
If i try domain2.com it redirects to domain1.com.

Configuration files:
domain1.com.conf

  <VirtualHost *:80>     
     ServerName domain1.com
     ServerAlias www.domain1.com
     DocumentRoot /var/www/html
   </VirtualHost>
   <IfModule mod_ssl.c>
     <VirtualHost *:443>
       DocumentRoot /var/www/html
       ServerName www.domain1.com
       Include /etc/letsencrypt/options-ssl-apache.conf
       SSLCertificateFile /etc/letsencrypt/live/domain1.com/fullchain.pem
       SSLCertificateKeyFile /etc/letsencrypt/live/domain1.com/privkey.pem
     </VirtualHost>
   </IfModule>

domain2.com.conf

   <VirtualHost *:80>
           ServerName domain2.com
           ServerAlias www.domain2.com
           DocumentRoot /var/www/public_html/domain2.com/wordpress
   </VirtualHost>
   <IfModule mod_ssl.c>
   <VirtualHost *:443>
           ServerAdmin gneri94@gmail.com
           DocumentRoot /var/www/public_html/domain2.com/wordpress
           ServerName www.domain2.com
           Include /etc/letsencrypt/options-ssl-apache.conf
           SSLCertificateFile /etc/letsencrypt/live/domain2.com/fullchain.pem
           SSLCertificateKeyFile /etc/letsencrypt/live/domain2.com/privkey.pem
   </VirtualHost>
   </IfModule>


.htaccess in both sites

# BEGIN WordPress                         
  RewriteEngine On 
  RewriteBase / 
  RewriteRule ^index\.php$ - [L] 
  RewriteCond %{REQUEST_FILENAME} !-f 
  RewriteCond %{REQUEST_FILENAME} !-d 
  RewriteRule . /index.php [L] 


command certbot certificates returns:

Certificate Name: domain1.com
Domains: domain1.com www.domain1.com
Certificate Path: /etc/letsencrypt/live/domain1.com/fullchain.pem
Private Key Path: /etc/letsencrypt/live/domain1.com/privkey.pem

Certificate Name: domain2.com
Domains: domain2.com www.domain2.com
Certificate Path: /etc/letsencrypt/live/domain2.com/fullchain.pem
Private Key Path: /etc/letsencrypt/live/domain2.com/privkey.pem

1
  • Have you tried from an alternative browser? It could be cache related.
    – davidgo
    May 26, 2020 at 4:03

1 Answer 1

1

For port 80 vHost you have:

ServerName domain2.com
ServerAlias www.domain2.com

But for port 443 you only have:

ServerName www.domain2.com

(This applies to both domain1 and domain2.)

So if you access https://domain2.com it will get caught by the default vHost (ie. the first one that is defined: www.domain1.com)

You should also consider redirecting to the HTTPS (canonical) domain in the port 80 vHost.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.