# Atlas Cargo Express - Apache configuration
# Works on: root domain, subdomain, or subfolder installation
#
# IMPORTANT: 
# - For ROOT domain: Use as-is
# - For SUBFOLDER: Update ErrorDocument 404 path (line 29)

# Set Directory Index (load index.php by default)
DirectoryIndex index.php index.html

# Enable Rewrite Engine
RewriteEngine On

# Force HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Redirect www to non-www (uncomment if needed)
# RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
# RewriteRule ^(.*)$ https://%1/$1 [L,R=301]

# Robots.txt endpoint
RewriteRule ^robots\.txt$ robots.php [L]

# Base directory - no RewriteBase so Apache auto-resolves
# Works on both subfolder and root domain

# Custom 404 Error Page
# IMPORTANT: Update this path based on your deployment
#
# For ROOT DOMAIN (yourdomain.com):
ErrorDocument 404 /404.php
#
# For SUBFOLDER (yourdomain.com/logitrack):
# ErrorDocument 404 /logitrack/404.php
#
# For SUBDOMAIN (app.yourdomain.com):
ErrorDocument 404 /404.php

# ============================================
# SECURITY ENHANCEMENTS
# ============================================

# Security: Block access to hidden files and directories
<FilesMatch "^\.">
    Order allow,deny
    Deny from all
</FilesMatch>

# Prevent directory browsing
Options -Indexes

# Protect sensitive files
<FilesMatch "\.(env|log|sql|bak|old|tmp|swp|dist)$">
    Order allow,deny
    Deny from all
</FilesMatch>

# Protect configuration and include files
<FilesMatch "^(config\.php|db\.php|auth\.php|functions\.php|security\.php)$">
    Order allow,deny
    Deny from all
</FilesMatch>

# Protect database files
<FilesMatch "\.(sql|db|sqlite)$">
    Order allow,deny
    Deny from all
</FilesMatch>

# Protect backup files
<FilesMatch "\.(bak|backup|old|orig|save|swp|tmp)$">
    Order allow,deny
    Deny from all
</FilesMatch>

# logs/, database/, includes/ and vendor/ each have an .htaccess that denies all access

# uploads/.htaccess blocks PHP files inside uploads

# Disable server signature
ServerSignature Off

# Enable GZIP compression
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json
</IfModule>

# 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/svg+xml "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"
    ExpiresByType font/woff "access plus 1 year"
    ExpiresByType font/woff2 "access plus 1 year"
    ExpiresByType application/font-woff "access plus 1 year"
    ExpiresByType application/font-woff2 "access plus 1 year"
</IfModule>
