1

I have two websites, call them example-1.com and example-2.com deployed on the same server (CentOS 7.5) both served by apache at port 80. The redirection is performed with Virtual hosts (see below for the full configuration).

For both sites I redirect (permanently) the non http urls to https (no problem with the certificates, bot work fine).

The problem I encounter is that the http version of the second website redirects (moved permanently, 301) to the https of the first one (the order of the sites is according to the .conf files below).

This redirect does not happen with the second website redirecting to the first (see the confs below), also everything works as it should if there is no need to redirect from http to https, i.e. I start with https://www.example-2.com .

Here are the .conf files, any ideas on how to fix this would be much appreciated.

Listen 80

<VirtualHost *:80>
    ServerName example-1.com
    Redirect permanent / https://www.example-1.com/
</VirtualHost>

<IfModule mod_ssl.c>
<VirtualHost *:443>
    DocumentRoot "/var/www/html/example-1"
    ServerName www.example-1.com
    ServerAlias example-1.com

## logging
   ErrorLog "/var/log/httpd/example-1-error_log"
   CustomLog "/var/log/httpd/example-1-access_log" combined

        <Directory "/var/www/html/example-1">
                DirectoryIndex index.html index.php
                Options FollowSymLinks
                AllowOverride All
       </Directory>
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/example-1.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example-1.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/example-1.com/chain.pem
</VirtualHost>
</IfModule>
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/css application/x-javascript text/x-component text/html text/plain text/xml application/javascript
</IfModule>

and the conf of the second website (notice that the only difference, except names, is that in this second one we do not have the Listen 80 at the top)

<VirtualHost *:80>
    ServerName example-2.com
    Redirect permanent / https://www.example-2.com/
</VirtualHost>

<IfModule mod_ssl.c>
<VirtualHost *:443>
    DocumentRoot "/var/www/html/example-2"
    ServerName www.example-2.com
    ServerAlias example-2.com

## logging
   ErrorLog "/var/log/httpd/example-2-home-error_log"
   CustomLog "/var/log/httpd/example-2-home-access_log" combined

        <Directory "/var/www/html/example-2">
                DirectoryIndex index.html index.php
                Options FollowSymLinks
                AllowOverride All
        </Directory>
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/example-2.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example-2.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/example-2.com/chain.pem
</VirtualHost>
</IfModule>
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/css application/x-javascript text/x-component text/html text/plain text/xml application/javascript
</IfModule>
2

I think I've finally located what was wrong in my configuration. I'm posting it here just in case anyone will have a similar problem.

I changed the server names to www equivalents and added server aliases without www, namely the directives now become

<VirtualHost *:80>
    ServerName www.example-1.com
    ServerAlias example-1.com
    Redirect permanent / https://www.example-1.com/
</VirtualHost>

and the same adjustment for the second website. This settled the incorrect redirection problem for me.

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.