Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.