#
# DO NOT MODIFY THIS FILE DIRECTLY.
# USE THE APACHE CONF FILES TO ALTER SETTINGS.
#

#No folder listing
Options -Indexes

AddType application/x-java-jnlp-file .jnlp
AddType application/x-web-app-manifest+json .webapp

<Files "ldap.php">
        Require all denied
</Files>
<Files "update.php">
        Require all denied
</Files>
<Files "config.php">
        Require all denied
</Files>
<Files "database.php">
        Require all denied
</Files>
<Files ~ "\.(bat)$"> 
        Require all denied
</Files>
<FilesMatch "log-2.*\.php">
    Require all denied
</FilesMatch>

<IfModule !env_module>
    DirectoryIndex install.php
</IfModule>

<IfModule env_module>
    DirectoryIndex index_us.php index.html

    SetEnv HTTP_MOD_ENV On

    <IfModule rewrite_module>
        SetEnv HTTP_MOD_REWRITE On

        RewriteEngine On
        #RewriteBase /

        #Redirects for dav, when untermStrich is installed in the root directory
        RewriteRule ^\.well-known/caldav https://%{HTTP_HOST}/dav [R=301,L]
        RewriteRule ^\.well-known/carddav https://%{HTTP_HOST}/dav [R=301,L]

        #Block access to certain directories
        RewriteRule ^application/(.*)$ select.html [L]
        RewriteRule ^exec/(.*)$ select.html [L]
        RewriteRule ^installer/(.*)$ select.html [L]
        RewriteRule ^java/(.*)$ select.html [L]
        RewriteRule ^system/(.*)$ select.html [L]
        RewriteRule ^writeable/cache/(.*)$ select.html [L]
        RewriteRule ^writeable/logs/(.*)$ select.html [L]
        RewriteRule ^writeable/temp/(.*)$ select.html [L]
        RewriteRule ^writeable/updates/(.*)$ select.html [L]

        RewriteRule ^(css|cssc|js|jsc|mobile_assets)/(.*)__[\.\d]*\.(css|js)$ $1/$2.$3 [L]
        
        RewriteRule ^static/js/(.*)$ jsc/chunks/$1 [L]

        #CGI mode PHP auth fix
        SetEnvIfNoCase Authorization "Basic ([a-z0-9=]+)" US_HTTP_AUTHORIZATION=$1

        #Checks to see if the user is attempting to access a valid file,
        #such as an image or css document, if this isn't true it sends the
        #request to index_us.php
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index_us.php?/$1 [PT,L]
    </IfModule>

    <IfModule !rewrite_module>
        DirectoryIndex install.php
    </IfModule>

    <IfModule !php5_module>
        <IfModule !php7_module>
            DirectoryIndex install.html
        </IfModule>
    </IfModule>

    <IfModule php5_module>
        php_flag register_globals off
        php_flag magic_quotes_gpc off
        php_value memory_limit 1350M
        php_value upload_max_filesize 50M
        php_value post_max_size 55M
        php_value max_input_time 600

        <Files "index_upload.php">
            php_value upload_max_filesize 2000M
            php_value post_max_size 2048M
        </Files>
    </IfModule>
    <IfModule php7_module>
        php_flag register_globals off
        php_flag magic_quotes_gpc off
        php_value memory_limit 1350M
        php_value upload_max_filesize 50M
        php_value post_max_size 55M
        php_value max_input_time 600

        <Files "index_upload.php">
            php_value upload_max_filesize 2000M
            php_value post_max_size 2048M
        </Files>
    </IfModule>
    #PHP 8
    <IfModule php_module>
        php_flag register_globals off
        php_flag magic_quotes_gpc off
        php_value memory_limit 1350M
        php_value upload_max_filesize 50M
        php_value post_max_size 55M
        php_value max_input_time 600

        <Files "index_upload.php">
            php_value upload_max_filesize 2000M
            php_value post_max_size 2048M
        </Files>
    </IfModule>

    <IfModule expires_module>
            SetEnv HTTP_MOD_EXPIRES On

            ExpiresActive On
            ExpiresByType image/gif "access plus 10 month"
            ExpiresByType image/jpeg "access plus 10 month"
            ExpiresByType image/png "access plus 10 month"

        # Lange Cache-Zeit für versionierte CSS/JS-Dateien
        <FilesMatch "\.(css|js)$">
            <If "%{REQUEST_URI} =~ /__[\.\d]+\.(css|js)$/">
                ExpiresActive On
                ExpiresDefault "access plus 1 month"
                <IfModule headers_module>
                    Header append Cache-Control "public, immutable"
                </IfModule>
            </If>
            <Else>
                ExpiresActive On
                ExpiresDefault "access plus 1 hour"
                <IfModule headers_module>
                    Header append Cache-Control "public, must-revalidate"
                </IfModule>
            </Else>
        </FilesMatch>

        # HTML-Dateien kurze Cache-Zeit
        <FilesMatch "\.html$">
            ExpiresActive On
            ExpiresDefault "access plus 1 hour"
        </FilesMatch>

        <FilesMatch "\.(ico|gif|jpg|jpeg|png|apng|svg|ttf|woff|woff2|eot)$">
            ExpiresActive On
            ExpiresDefault "access plus 1 day"
        </FilesMatch>
    </IfModule>

    <IfModule !expires_module>
            DirectoryIndex install.php
    </IfModule>

    <IfModule deflate_module>
            AddOutputFilterByType DEFLATE text/html text/plain text/css application/javascript
    </IfModule>

</IfModule>
