# Apache .htaccess configuration for KGN Sliding Window Solutions
RewriteEngine On

# Disable Directory Browsing
Options -Indexes

# 1. Redirect direct .php requests to clean extensionless URLs (301 Permanent Redirect)
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteCond %{REQUEST_URI} !^/includes/ [NC]
RewriteCond %{REQUEST_URI} ^(.+)\.php$ [NC]
RewriteRule ^ %1 [R=301,L]

# 2. Internally map clean URL to root .php file if it exists
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ $1.php [L]

# 3. Internally map clean URL to locations/ folder if it exists in locations/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/sli/slide/locations/$1.php -f
RewriteRule ^(.+)$ locations/$1.php [L]

# 4. Fallback map for production domain root /locations/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/locations/$1.php -f
RewriteRule ^(.+)$ locations/$1.php [L]

# Gzip Compression for Fast Loading
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript application/json
</IfModule>

# Leverage Browser Caching
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/jpg "access plus 1 year"
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/gif "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/webp "access plus 1 year"
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"
</IfModule>
