-1

I've following VirtualHost configured:

<VirtualHost *:80>
    ServerAdmin     [email protected]
    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

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

1 Answer 1

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     [email protected]
    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 .