#RewriteEngine on
<IfModule mod_rewrite.c>
    RewriteEngine On

    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    #Deny access to App/Storage files (cache)
    RewriteRule ^App/Storage/.*$ - [F,L]

    #Deny access to App/Package/*/Init files
    RewriteRule ^App/Package/.*/Init/.*$ - [F,L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]
    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

    # User Errors...
    ErrorDocument 401 /error/401
    ErrorDocument 403 /error/403
    ErrorDocument 404 /error/404
    ErrorDocument 500 /error/500
</IfModule>

# Deny access to App/Storage files
<FilesMatch "^App/Storage/.*">
    Require all denied
</FilesMatch>

# Deny access to all files starting with .
<Files ~ "^\.">
    Require all denied
</Files>

# Deny access to all .json files
<Files "*.json">
    Order allow,deny
    Deny from all
    satisfy all
</Files>

# Deny access to cmw file
<Files cmw>
    Require all denied
</Files>

# Deny access to pretty-php.phar file
<Files "pretty-php.phar">
    Require all denied
</Files>

# Deny access to LICENSE file
<Files "LICENSE">
    Require all denied
</Files>

# Deny access to docker files
<FilesMatch "Dockerfile|compose\.yaml|\.dockerignore|README.Docker\.md">
    Order allow,deny
    Deny from all
</FilesMatch>

#Cache images / scripts
<IfModule mod_expires.c>
    ExpiresActive on

    ExpiresDefault "access plus 1 week"

    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/webp "access plus 1 month"
    AddType image/x-icon .ico
    ExpiresByType image/x-icon "access plus 1 month"
    ExpiresByType image/icon "access plus 1 month"
    ExpiresByType image/ico "access plus 1 month"
    ExpiresByType image/svg+xml "access plus 1 month"

    ExpiresByType text/javascript "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"

    ExpiresByType text/css "access plus 1 month"

    ExpiresByType font/woff2  "access plus 1 year"
    ExpiresByType application/font-woff2  "access plus 1 year"
    ExpiresByType application/x-font-woff2  "access plus 1 year"
</IfModule>

<filesMatch ".(ico|jpg|jpeg|png|gif|js|css|webp|svg|woff2|otf)$">
    Header set Cache-Control "max-age=84600, public"
</filesMatch>

<IfModule mod_php5.c>
    #Session timeout
    php_value session.cookie_lifetime 600480 # 7 days
    php_value session.gc_maxlifetime 600480
</IfModule>
