5

I'm having trouble figuring out what's the proper way to setup a SSL virtual host + a non-SSL copy of it.

I have it like this now:
<VirtualHost myip:80>
plenty of directives here
</VirtualHost>

and

<VirtualHost myip:443>
same directives as above
</VirtualHost>

And it works fine but every time I edit the directives in one of the vhosts, I must do it in the other as well. Anything cleaner and more elegant?

Amati
  • 1,484
  • 1
  • 16
  • 29
  • A duplicate of http://serverfault.com/questions/83669/apache2-with-ssl-do-i-have-to-copy-virtualhost-blocks and of http://stackoverflow.com/questions/679383/do-i-have-to-duplicate-the-virtualhost-directives-for-port-80-and-443 – Joachim Breitner Dec 09 '12 at 12:42

1 Answers1

7

To run a website on both HTTP and HTTPS URLs, your only option is to run 2 separate VirtualHosts with the same DocumentRoot.

If the directives context allows, you can keep some of the common settings in a .htaccess file in a folder that is parent to both DocumentRoots.

rightstuff
  • 6,412
  • 31
  • 20
  • 7
    Thanks. I ended up using the Include directive inside VirtualHost and putting all common stuff in a separate file. – Amati May 01 '12 at 13:52