php_value upload_max_filesize 100M
php_value post_max_size 100M
php_value memory_limit -1
php_value max_execution_time 600
php_flag display_errors On
php_flag display_startup_errors On
php_flag zlib.output_compression On

Options -Indexes
#RequestHeader unset Accept-Encoding

AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/json

<IfModule mod_headers.c>
    # Serve gzip compressed CSS files if they exist 
    # and the client accepts gzip.
    RewriteCond "%{HTTP:Accept-encoding}" "gzip"
    RewriteCond "%{REQUEST_FILENAME}\.gz" -s
    RewriteRule "^(.*)\.css" "$1\.css\.gz" [QSA]

    # Serve gzip compressed JS files if they exist 
    # and the client accepts gzip.
    RewriteCond "%{HTTP:Accept-encoding}" "gzip"
    RewriteCond "%{REQUEST_FILENAME}\.gz" -s
    RewriteRule "^(.*)\.js" "$1\.js\.gz" [QSA]


    # Serve correct content types, and prevent mod_deflate double gzip.
    RewriteRule "\.css\.gz$" "-" [T=text/css,E=no-gzip:1]
    RewriteRule "\.js\.gz$" "-" [T=text/javascript,E=no-gzip:1]


    <FilesMatch "(\.js\.gz|\.css\.gz)$">
      # Serve correct encoding type.
      Header append Content-Encoding gzip

      # Force proxies to cache gzipped & 
      # non-gzipped css/js files separately.
      Header append Vary Accept-Encoding
    </FilesMatch>
</IfModule>

<IfModule mod_rewrite.c>

RewriteEngine On

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

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

#PHP extensions
RewriteRule ^([a-z]+)\/?$ $1.php [NC]
#RewriteRule (.*) $1.php [L]
#Easy fix for redirecting to the correct folder.
#RewriteRule ^([^\.]+)$ /api/$1.php [NC,L]

#Remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s]
RewriteRule ^(.+?)/$ /api/$1 [R=301,L]

#General REST API rewrites

#Mapping
RewriteRule ^mappings mapping.php [NC]
RewriteRule ^plugins\/(.+)\/devices\/(.+)\/items\/(.+)\/mappings\/?$ mapping.php?plugin=$1&device=$2&item=$3 [NC]
RewriteRule ^plugins\/(.+)\/devices\/(.+)\/mappings\/(.+)\/messages\/?$ mapping_messages.php?plugin=$1&device=$2&mapping=$3&%{QUERY_STRING} [NC]
RewriteRule ^plugins\/(.+)\/devices\/(.+)\/mappings\/?$ mapping.php?plugin=$1&device=$2 [NC]
RewriteRule ^plugins\/(.+)\/mappings\/(.+)\/messages\/?$ mapping_messages.php?plugin=$1&mapping=$2&%{QUERY_STRING} [NC]
RewriteRule ^plugins\/(.+)\/mappings\/?$ mapping.php?plugin=$1 [NC]
RewriteRule ^mapping_groups\/(.+)\/mappings\/?$ mapping.php?mapping_group=$1 [NC]

#Mapping Groups
RewriteRule ^mapping_groups\/(.+)\/remain\/?$ mapping_groups.php?mapping_group=$1&remain=true&%{QUERY_STRING} [NC]
RewriteRule ^mapping_groups\/(.+)\/?$ mapping_groups.php?mapping_group=$1 [NC]
RewriteRule ^mapping_groups mapping_groups.php [NC]

#Items
#RewriteRule ^plugins\/([a-z]+)\/([0-9]+)\/?$ parameter_letter_and_number.php?param=$1&param2=$2 [NC]
RewriteRule ^plugins\/(.+)\/devices\/(.+)\/items\/?$ item.php?plugin=$1&device=$2 [NC]
RewriteRule ^plugins\/(.+)\/devices\/(.+)\/items\/(.+)\/write\/?$ data.php?plugin=$1&device=$2&item=$3 [NC]
RewriteRule ^plugins\/(.+)\/devices\/(.+)\/items\/(.+)\/data\/?$ data.php?plugin=$1&device=$2&item=$3&%{QUERY_STRING} [NC]
RewriteRule ^plugins\/(.+)\/devices\/(.+)\/items\/(.+)\/read\/?$ read.php?plugin=$1&device=$2&item=$3 [NC]
RewriteRule ^plugins\/(.+)\/devices\/(.+)\/items\/(.+)\/(.+)?$ item.php?plugin=$1&device=$2&item=$3 [NC]
RewriteRule ^plugins\/(.+)\/devices\/(.+)\/items\/(.+)?$ item.php?plugin=$1&device=$2&item=$3 [NC]

#Files
RewriteRule ^plugins\/(.+)\/devices\/(.+)\/files\/?$ file.php?plugin=$1&device=$2&%{QUERY_STRING} [NC]
RewriteRule ^plugins\/(.+)\/devices\/(.+)\/files\/(.+)\/?$ file.php?plugin=$1&device=$2&file=$3&%{QUERY_STRING} [NC]
RewriteRule ^plugins\/(.+)\/files\/(.+)\/?$ file.php?plugin=$1&file=$2&%{QUERY_STRING} [NC]
RewriteRule ^plugins\/(.+)\/files\/?$ file.php?plugin=$1&%{QUERY_STRING} [NC]
RewriteRule ^files\/(.+)\/?$ file.php?file=$1&%{QUERY_STRING} [NC]
RewriteRule ^files file.php%{QUERY_STRING} [NC]

#Data
RewriteRule ^plugins\/(.+)\/devices\/(.+)\/data\/?$ data.php?plugin=$1&device=$2&%{QUERY_STRING} [NC]
RewriteRule ^plugins\/(.+)\/devices\/(.+)\/data\/(.+)?$ data.php?plugin=$1&device=$2&%{QUERY_STRING} [NC]
RewriteRule ^plugins\/(.+)\/devices\/data\/?$ data.php?plugin=$1&%{QUERY_STRING} [NC]
RewriteRule ^plugins\/(.+)\/data\/?$ data.php?plugin=$1&%{QUERY_STRING} [NC]

#Device
RewriteRule ^plugins\/(.+)\/devices\/?$ device.php?plugin=$1 [NC]
RewriteRule ^plugins\/(.+)\/devices\/(.+)\/read\/?$ read.php?plugin=$1&device=$2 [NC]
RewriteRule ^plugins\/(.+)\/devices\/(.+)\/(.+)?$ device.php?plugin=$1&device=$2 [NC]
RewriteRule ^plugins\/(.+)\/devices\/(.+)\/?$ device.php?plugin=$1&device=$2 [NC]
RewriteRule ^devices device.php [NC]

#Plugin
RewriteRule ^plugins\/(.+)\/?$ plugin.php?plugin=$1 [NC]
RewriteRule ^plugins plugin.php [NC]

#Network
RewriteRule ^networks\/(.+)\/?$ network.php?network=$1 [NC]
RewriteRule ^networks network.php [NC]

#Setting
RewriteRule ^settings\/(.+)\/?$ setting.php?setting=$1 [NC]
RewriteRule ^settings setting.php [NC]

#Setup
RewriteRule ^setup\/(.+)\/?$ setup.php?option=$1 [NC]
RewriteRule ^setup setup.php [NC]

#User
RewriteRule ^users\/(.+)\/?$ user.php?username=$1 [NC]
RewriteRule ^users user.php [NC]

#License
RewriteRule ^licenses\/(.+)\/?$ license.php?license=$1 [NC]
RewriteRule ^licenses license.php [NC]

#License
RewriteRule ^versions version.php [NC]

#Import
RewriteRule ^import import.php [NC]

#Updater
RewriteRule ^updater\/(.+)\/?$ updater.php?mode=$1 [NC]
RewriteRule ^updater updater.php [NC]

#Tools
##DigiCert ONE IoT Trust
RewriteRule ^tools\/digicert_one_iot_trust\/?$ digicert_one_iot_trust.php [NC]
RewriteRule ^tools\/systemresources\/?$ systemresources.php [NC]

##Services
RewriteRule ^tools\/(.+)\/?$ tools.php?service=$1 [NC]
RewriteRule ^tools tools.php [NC]



#Containers
RewriteRule ^containers\/(.+)\/start\/?$ containers.php?container=$1&command=start&%{QUERY_STRING} [NC]
RewriteRule ^containers\/(.+)\/stop\/?$ containers.php?container=$1&command=stop&%{QUERY_STRING} [NC]
RewriteRule ^containers\/(.+)\/?$ containers.php?container=$1&%{QUERY_STRING} [NC]

#Secomea
RewriteRule ^remote_access\/secomea secomea.php [NC]
RewriteRule ^secomea secomea.php [NC]

#Restart - Soft & Hard (match exact ^start of word, $end of word)
RewriteRule ^soft_restart$ restart.php?soft [NC]
RewriteRule ^hard_restart$ restart.php?hard [NC]

#GramExporter
RewriteRule ^gramexport\/(.+)\/?$ exportgram.php?type=$1 [NC]
RewriteRule ^gramexport\/(.+)\/?$ exportgram.php?info=$1 [NC]
RewriteRule ^gramexport\/(.+)\/?$ exportgram.php?cancel=$1 [NC]
RewriteRule ^gramexport exportgram.php [NC]

</IfModule>
