Run HTTP and HTTPS Simultaneously on Same Domain

Last modified: 
Monday, October 19th, 2015
Topics: 
MampApache

If you need to run HTTP and HTTPS simultaneously on the same domain, create a VirtualHost declaration for example.com:80 and another for example.com:443. The following example is based on a local setup using MAMP, but the idea is the same for a Vagrant box or production machine.

 
<VirtualHost example.org:80>
  ServerName example.org
  ServerAlias www.example.org
  DocumentRoot "/var/www/example/docroot"
  SetEnv APP_ENV "LOCAL"
  ErrorLog /var/www/example/assets/logs/example_error.log
  <Directory /var/www/example/docroot>
    AllowOverride All
  </Directory>
</VirtualHost>

<VirtualHost example.org:443>
  ServerName example.org
  ServerAlias www.example.org
  DocumentRoot "/var/www/example/docroot"
  SetEnv APP_ENV "LOCAL"
  ErrorLog /var/www/example/assets/logs/example_error.log
  <Directory /var/www/example/docroot>
    AllowOverride All
  </Directory>
  SSLEngine on
  SSLCertificateFile /Applications/MAMP/conf/apache/server.crt
  SSLCertificateKeyFile /Applications/MAMP/conf/apache/server.key
</VirtualHost>


The operator of this site makes no claims, promises, or guarantees of the accuracy, completeness, originality, uniqueness, or even general adequacy of the contents herein and expressly disclaims liability for errors and omissions in the contents of this website.