Options -Indexes
Options +FollowSymLinks

# ============================================================
# SECURITY HEADERS
# ============================================================
<IfModule mod_headers.c>
    Header always set X-Content-Type-Options "nosniff"
    Header always set X-Frame-Options "SAMEORIGIN"
    Header always set X-XSS-Protection "1; mode=block"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>

# ============================================================
# URL REWRITING - Remove .php Extension
# ============================================================
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # Block access to sensitive files
    RewriteRule ^config\.php$ - [F,L]
    # RewriteRule ^set_db\.php$ - [F,L]
    RewriteRule ^\.env$ - [F,L]

    # Block direct access to upload directories (except images via proper routes)
    # RewriteRule ^uploads/docs/(.*)$ - [F,L]

    # If request is for real file or directory, serve it
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    # Remove .php extension
    RewriteRule ^([^\.]+)$ $1.php [NC,L]

    # Handle subdirectory routing
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([a-zA-Z0-9_-]+)/([^\.]+)$ $1/$2.php [NC,L]
</IfModule>

# ============================================================
# BLOCK ACCESS TO SENSITIVE FILES
# ============================================================
<FilesMatch "\.(htaccess|htpasswd|ini|log|sh|sql|env)$">
    Order Allow,Deny
    Deny from all
</FilesMatch>

# ============================================================
# PHP SETTINGS
# ============================================================
<IfModule mod_php.c>
    php_value upload_max_filesize 10M
    php_value post_max_size 12M
    php_value max_execution_time 300
    php_value memory_limit 256M
</IfModule>

# ============================================================
# GZIP COMPRESSION
# ============================================================
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/plain text/html text/css application/javascript application/json
</IfModule>

# ============================================================
# BROWSER CACHING
# ============================================================
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/webp "access plus 1 month"
    ExpiresByType text/css "access plus 1 week"
    ExpiresByType application/javascript "access plus 1 week"
</IfModule>

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php81” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php81 .php .php8 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
