2

I have all my domains in a single vhosts.conf file that I have rsync across three servers. All three for some reason do not redirect http://example.com to https://example.com but will redirect http://example.net to https://example.net. Instead, http://example.com will just show the default page.

I have rewrite, ssl, headers, and env enabled as well. Apache was reloaded and also restarted. Debian 8 with Apache2. I removed the VirtualHost for port 443 (SSL) to shorten the conf file.

# example.com
<VirtualHost *:80>
        ServerName example.com
        ServerAlias www.example.com
        ServerAdmin [email protected]

        Redirect permanent / https://example.com/

        LogLevel info
        ErrorLog ${APACHE_LOG_DIR}/example.com_error.log
        CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined
</VirtualHost>

# example.net
<VirtualHost *:80>
        ServerName example.net
        ServerAlias www.example.net
        ServerAdmin [email protected]

        Redirect permanent / https://example.net/

        LogLevel info
        ErrorLog ${APACHE_LOG_DIR}/example.net_error.log
        CustomLog ${APACHE_LOG_DIR}/example.net_access.log combined
</VirtualHost>

2 Answers 2

3

They do not redirect because the first virtualhost which does not have a server name is probably grabbing all requests.

Always define ServerName for each virtualhost.

2
  • 1
    Still not working, it just picks the next virtualhost section that's on top. Each one has a ServerName defined too. Jun 16, 2017 at 20:48
  • This answer worked for me.
    – Geoffrey
    Dec 16, 2023 at 2:56
0

I had ServerAdmin spelled wrong on one of the virtual host blocks.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .