Apache2 redirect not working properly

apache-2.4debian-jessie

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 webmaster@example.com

        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 webmaster@example.net

        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>

Best Answer

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.

Related Topic