<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName api.skoula.cz
    ServerAlias www.api.skoula.cz
    DocumentRoot /var/www/api.skoula.cz
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    RewriteEngine on

    # https/http www -> https non-www
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ https://%1$1 [R=301,L]

    # http non-www -> https non-www
    RewriteCond %{HTTPS} !=on
    RewriteRule ^/?(.*) https://%{SERVER_NAME}$1 [R,L]

RewriteCond %{SERVER_NAME} =api.skoula.cz [OR]
RewriteCond %{SERVER_NAME} =www.api.skoula.cz
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

<Directory /var/www/api.skoula.cz>
    Require all granted
    AllowOverride All
    Header set Access-Control-Allow-Origin "*"
 </Directory>
 
</VirtualHost>
