-1

This question already has an answer here:

I've following VirtualHost configured:

<VirtualHost *:80>
    ServerAdmin     mymail@mymail.com
    DocumentRoot    /var/www/mysite.com/public_html/
    ServerName      www.mysite.com
    ServerAlias     mysite.com

    <Directory "/var/www/mysite.com/public_html">
        #Options FollowSymLinks
        #AllowOverride All
        #Order allow,deny
        #Allow from all
      Options Indexes FollowSymLinks
      AllowOverride All
      Order allow,deny
      Allow from all
      Require all granted
    </Directory>

I'd like:

  1. to enforce a https-only connection
  2. and allow a connection when the user uses mysite.com without www

How to do that?

Thanks

marked as duplicate by Iain, Thomas, Esa Jokinen, Community May 4 at 16:34

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • that's not a VirtualHost configuration. Especially it isn't one that would allow HTTPS – Andreas Rogge May 3 at 19:38
  • 1
    Also this question has already been answered a lot: serverfault.com/questions/683383/… – Andreas Rogge May 3 at 19:41
  • If you use the on site search facility you will find many examples of this. – Iain May 4 at 7:29
1

First, you should have 443 port virtual host definition for HTTPS.

Second, add a rewrite rule from port 80 to 443.

Sample fragments:

<VirtualHost __default_:443>
    ServerAdmin     mymail@mymail.com
    DocumentRoot    /var/www/mysite.com/public_html/
    ServerName      www.example.com
    ServerAlias     example.com
    SSLEngine       On
    ...
</VirtualHost>

<VirtualHost *:80> 
    ServerName www.yourdomain.com 
    Redirect permanent / https://www.example.com/ 
</VirtualHost>

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