allow from all

#Header Set Service-Worker-allowed "/"

RewriteEngine On

## Rewrite http to https (For the case host is not start with www)
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} !=localhost
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} !^137\.59\.109\.82 [NC] ## Host is not start with 137.59.109.82 (Server IP)
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,QSA,NC,L]

## Rewrite www. to non-www, at the same time make sure it is https
RewriteCond %{HTTP_HOST} !=localhost
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [R=301,QSA,NC,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php