0

My website has an SSL cert (example url: https://subdomain.example.com). Under Apache it's set up for both port 80 and port 443. So under the following configuration, anyone who goes to http://subdomain.example.com is sent to https://subdomain.example.com . But for visits from Internet Explorer, the redirect doesn't happen. Instead, http visits get a "Internet Explorer cannot display the web page." with a list of client-side solutions to try.

Any ideas on how to fix the config so IE visits have the same behavior as the other browsers (that is, send http to https automatically)?

NameVirtualHost *:443

<VirtualHost *:80>
  DocumentRoot /var/www/somewebroot
  ServerName subdomain.example.com
</VirtualHost>

<VirtualHost *:443>
     DocumentRoot /var/www/somewebroot
     ServerName subdomain.example.com
    #   SSL CERTS HERE
</VirtualHost>

*Tested IE8, IE9 beta

Kyle Cureau
  • 1,537
  • 3
  • 11
  • 15

1 Answers1

1

Placing this code in the HTTP virtual host's definition should do it.

RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^/(.*) https://subdomain.example.com [R=301,L]

If you are testing changes you may have problems with IE unless you shut down all IE windows and restart. IE can be use its cache aggressively.

EDIT: You need to ensure mod_rewrite is enabled. Command is a2enmod rewrite. It will tell you if the module is already enabled. If not you will need to shutdown and restart the server after enabling the module.

Add the lines above to your virtual host definition and use apache2ctl graceful to reload the modified configuration. The Apache documentation has details on rewriting.

You should see the redirect as a 301 status request in your access log followed by a 200 or 304 status on the HTTPS connection. The displayed URL should change to the new location.

Logging the port in an extend log format helps to see which connection things are happening on. Alternatively, use separate logs for each virtual server.

BillThor
  • 27,354
  • 3
  • 35
  • 69