php_value upload_max_filesize 256M
php_value post_max_size 256M
php_value memory_limit -1
php_value max_execution_time 600
php_flag display_errors Off
php_flag display_startup_errors Off
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&%{QUERY_STRING} [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&%{QUERY_STRING} [NC]
RewriteRule ^plugins\/(.+)\/mappings\/(.+)\/messages\/?$ mapping_messages.php?plugin=$1&mapping=$2&%{QUERY_STRING} [NC]
RewriteRule ^plugins\/(.+)\/mappings\/?$ mapping.php?plugin=$1&%{QUERY_STRING} [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\/(.+)\/tags\/?$ item_tags.php?plugin=$1&device=$2&item=$3&%{QUERY_STRING} [NC]
RewriteRule ^plugins\/(.+)\/devices\/(.+)\/item_tags\/?$ item_tags.php?plugin=$1&device=$2&%{QUERY_STRING} [NC]
RewriteRule ^plugins\/(.+)\/devices\/(.+)\/items\/?$ item.php?plugin=$1&device=$2&%{QUERY_STRING} [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&%{QUERY_STRING} [NC]
RewriteRule ^plugins\/(.+)\/devices\/(.+)\/items\/(.+)?$ item.php?plugin=$1&device=$2&item=$3&%{QUERY_STRING} [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&%{QUERY_STRING} [NC]
RewriteRule ^plugins\/(.+)\/devices\/(.+)\/read\/?$ read.php?plugin=$1&device=$2 [NC]
RewriteRule ^plugins\/(.+)\/devices\/(.+)\/(.+)?$ device.php?plugin=$1&device=$2&%{QUERY_STRING} [NC]
RewriteRule ^plugins\/(.+)\/devices\/(.+)\/?$ device.php?plugin=$1&device=$2&%{QUERY_STRING} [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]

#System notifications
RewriteRule ^system_notification_events\/?$ system_notifications.php?action=events [NC,QSA,L]
RewriteRule ^notification_mutes\/?$ notification_mutes.php [NC,QSA,L]
RewriteRule ^system_notifications\/([0-9]+)\/dismiss\/?$ system_notifications.php?notification=$1&action=dismiss [NC,L]
RewriteRule ^system_notifications\/(.+)\/?$ system_notifications.php?notification=$1 [NC]
RewriteRule ^system_notifications system_notifications.php [NC]

#Asset inventory (instances + tagged items + live values)
RewriteRule ^inventory\/reserved_tags\/?$ inventory.php?reserved_tags=1 [NC,QSA]
RewriteRule ^inventory\/tags\/(.+)/?$ inventory.php?tags=1&tag=$1 [NC,QSA]
RewriteRule ^inventory\/tags\/?$ inventory.php?tags=1 [NC,QSA]
RewriteRule ^inventory\/?$ inventory.php [NC,QSA]

#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\/install containers.php?install [NC]
RewriteRule ^containers\/uninstall containers.php?uninstall [NC]
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]

#Remote access
RewriteRule ^remote_access\/secomea secomea.php [NC]
RewriteRule ^secomea secomea.php [NC]
RewriteRule ^remote_access\/netbird\/start netbird.php?start [NC]
RewriteRule ^remote_access\/netbird\/stop netbird.php?stop [NC]
RewriteRule ^remote_access\/netbird netbird.php [NC]
RewriteRule ^netbird netbird.php [NC]
RewriteRule ^remote_access\/zrok zrok.php [NC]
RewriteRule ^zrok zrok.php [NC]

#TosiBox
RewriteRule ^remote_access\/tosibox tosibox.php [NC]
RewriteRule ^tosibox tosibox.php [NC]

#Fleet
RewriteRule ^fleet\/install\/?$ fleet.php?action=install [NC,QSA]
RewriteRule ^fleet\/status\/?$ fleet.php?action=status [NC,QSA]
RewriteRule ^fleet\/registration_otp\/?$ fleet.php?action=registration_otp [NC,QSA]
RewriteRule ^fleet\/start\/?$ fleet.php?action=start [NC,QSA]
RewriteRule ^fleet\/stop\/?$ fleet.php?action=stop [NC,QSA]
RewriteRule ^fleet\/prepare_reregistration\/?$ fleet.php?action=prepare_reregistration [NC,QSA]
RewriteRule ^fleet\/rotate_cert\/?$ fleet.php?action=rotate_cert [NC,QSA]
RewriteRule ^fleet\/unregister\/?$ fleet.php?action=unregister [NC,QSA]
RewriteRule ^fleet\/tenant_url\/?$ fleet.php?action=tenant_url [NC,QSA]
RewriteRule ^fleet\/setup\/?$ fleet.php?action=setup [NC,QSA]
RewriteRule ^fleet\/?$ fleet.php [NC,QSA]

#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]

</IfModule>
