Search code examples
httpsslhttp-redirecthttps

Why are my http sites not redirecting to https?


I have been trying to get all of my company's http sites to automatically redirect over to https.

In my httpd.conf file, I have the following:

<VirtualHost *:80>
  ServerName internal.va.com
  Redirect / https://internal.va.com
</VirtualHost>

<VirtualHost _default_:443>
  ServerName internal.va.com
  DocumentRoot "D:/htdocs"
  SSLEngine On
</VirtualHost>

When using SSLEngine On, restarting Apache gives me the following error message:

enter image description here

When I comment out SSLEngine On, I no longer get the message, but the sites are not redirecting.

Additionally, I am not sure if I should be adding the server IP address in the VirtualHost tags.

For example:

<VirtualHost 112.245.154.47:80>
// same info as above
</VirtualHost>

<VirtualHost 112.245.154.47:443>
// same info as above
</VirtualHost>

I am not sure if I should be using the server's IP address or if the VirtualHost tag should just include "*:80" and "_ default _:443".

I found this in the error log:

Failed to configure at least one certificate and key for internal.va.com:443

I understand this question may be a duplicate, but I have tried to follow the answers provided under the following questions:

None of the above questions have helped me solve my problem. I am still unable to get all of the http sites to redirect over to https.

What can I do to correctly redirect the http sites to https?


Solution

  • <VirtualHost _default_:443>
      ServerName internal.va.com
      DocumentRoot "D:/htdocs"
      SSLEngine On
    </VirtualHost>
    

    I found this in the error log: Failed to configure at least one certificate and key for internal.va.com:443

    With the config shown and this error message the problem is pretty obvious: you have SSL enabled but no certificate configured for a host. But HTTPS without a server certificate will not work.

    Note that this is completely unrelated to the redirect you are trying to attempt. It is only about configuring a proper HTTPS site.