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

    RewriteEngine On

    ##################################
    #                                #
    #  Compatibility with version 1  #
    #                                #
    ##################################

#    # Redirect Knowledgebase
#    RewriteCond %{QUERY_STRING} ^module=kb&sec=mainpage$ [NC]
#    RewriteRule ^index.php$ /support/knowledgebase? [R=302,L]
#
#    RewriteCond %{QUERY_STRING} ^module=kb&sec=category&cat_slug=([\w\W]+)$ [NC]
#    RewriteRule ^index.php$ /support/knowledgebase/category/%1? [R=302,L]
#
#    RewriteCond %{QUERY_STRING} ^module=kb&sec=article&artid=([0-9]+)&slug=([\w\W]+)$ [NC]
#    RewriteRule ^index.php$ /support/knowledgebase/article/%2? [R=302,L]
#
#    # Redirect Announcements
#    RewriteCond %{QUERY_STRING} ^module=announce&sec=mainpage$ [NC]
#    RewriteRule ^index.php$ /support/announcements? [R=302,L]
#
#    RewriteCond %{QUERY_STRING} ^module=announce&sec=mainpage&cat_slug=([\w\W]+)$ [NC]
#    RewriteRule ^index.php$ /support/announcements/category/%1? [R=302,L]
#
#    RewriteCond %{QUERY_STRING} ^module=announce&sec=view&id=([0-9]+)&slug=([\w\W]+)$ [NC]
#    RewriteRule ^index.php$ /support/announcements/article/%2? [R=302,L]
#
#    # Announcements RSS
#    RewriteCond %{QUERY_STRING} ^module=announce&sec=rss$ [NC]
#    RewriteRule ^index.php$ /support/announcements/rss? [R=302,L]
#
#    # Redirect Downloads
#    RewriteCond %{QUERY_STRING} ^module=downloads&sec=mainpage$ [NC]
#    RewriteRule ^index.php$ /support/downloads? [R=302,L]
#
#    RewriteCond %{QUERY_STRING} ^module=downloads&sec=category&cat_slug=([\w\W]+)$ [NC]
#    RewriteRule ^index.php$ /support/downloads/category/%1? [R=302,L]
#
#    RewriteCond %{QUERY_STRING} ^module=downloads&sec=download&downloadId=([0-9]+)&slug=([\w\W]+)$ [NC]
#    RewriteRule ^index.php$ /support/downloads/article/%2? [R=302,L]
#
#    # Redirect SEO articles
#    RewriteCond %{REQUEST_FILENAME} !-f
#    RewriteRule ^(knowledgebase|downloads|announcements)/([\w\W]+)-([0-9]+).html$ /support/$1/article/$2 [R=302,L]
#
#    # Redirect Tickets
#    RewriteCond %{QUERY_STRING} ^module=tickets&sec=track$ [NC]
#    RewriteRule ^index.php$ /support/tickets/track [R=302,L]
#
#    RewriteCond %{QUERY_STRING} ^module=tickets&sec=submit [NC]
#    RewriteRule ^index.php$ /support/tickets/create/step1 [R=302,L]
#
#    # Redirect User-based Links
#    RewriteCond %{QUERY_STRING} ^module=user&sec=register$ [NC]
#    RewriteRule ^index.php$ /support/register [R=302,L]
#
#    RewriteRule ^login.php /support/login [R=302,L]
#
#    RewriteCond %{QUERY_STRING} ^module=core&sec=search&search=([\w\W]+) [NC]
#    RewriteRule ^index.php$ /support/search?query=%1 [R=302,L]

    ##################################
    #             Laravel            #
    ##################################

    # HTTP authorisation.
    RewriteCond %{HTTP:Authorization} ^(.*)
    RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

    # Dynamically detect the base URL.
    # http://stackoverflow.com/questions/21062290/set-rewritebase-to-the-current-folder-path-dynamically
    # https://github.com/zendframework/zf1/blob/master/library/Zend/Tool/Project/Context/Zf/HtaccessFile.php
    RewriteCond %{REQUEST_URI}::$1 ^(.*?/)(.*)::\2$
    RewriteRule ^(.*)$ - [E=BASE:%1]

    # Remove index.php from the URL on GET calls.
    RewriteCond %{REQUEST_METHOD} ^GET
    RewriteCond %{THE_REQUEST} ^.*/index\.php
    RewriteRule ^index.php/?(.*)$ %{ENV:BASE}$1 [R=301,NE,L]

    # Redirect all URLs to index.php.
    RewriteCond %{REQUEST_FILENAME} !-f [OR]
    RewriteCond %{REQUEST_URI} !\.(css|gif|ico|je?pg|js|png|swf|txt|eot|ttf|woff|woff2|svg|map)$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-f [OR]
    RewriteCond %{REQUEST_URI} !resources/assets/ [NC]
    RewriteRule ^ index.php [L]
</IfModule>

<IfModule mod_headers.c>
    # Cache fonts, images, css and js for one month
    <FilesMatch ".(css|js|jpg|jpeg|png|gif|ico|svg|woff|woff2)$">
        Header set Cache-Control "max-age=2628000, public"
    </FilesMatch>
</IfModule>

# Permit OPTIONS, GET, POST, PUT and DELETE requests.
# Apache 2.2
<IfModule !mod_authz_core.c>
    <Limit OPTIONS GET POST PUT DELETE>
        Allow from all
    </Limit>
</IfModule>
# Apache 2.4
<IfModule mod_authz_core.c>
    <Limit OPTIONS GET POST PUT DELETE>
        Require all granted
    </Limit>
</IfModule>

# Compress HTML, CSS, JavaScript, Text, XML and fonts
<IfModule mod_filter.c>
    <IfModule mod_deflate.c>
        AddOutputFilterByType DEFLATE text/plain
        AddOutputFilterByType DEFLATE text/css
        AddOutputFilterByType DEFLATE text/javascript
        AddOutputFilterByType DEFLATE application/json
        AddOutputFilterByType DEFLATE application/javascript
    </IfModule>
</IfModule>
