# KSO Chandigarh Admin Panel - URL Rewriting Configuration
# This file handles clean URLs by hiding file extensions

# Enable the rewrite engine
RewriteEngine On

# Set the base directory if needed
# If your site is in a subdirectory, uncomment and modify this:
# RewriteBase /adminlte/

# Prevent direct access to this file
<Files .htaccess>
    Order Allow,Deny
    Deny from all
</Files>

# Prevent direct access to sensitive directories
RedirectMatch 403 ^/adminlte/(config|logs|database)/.*$

# Don't rewrite if the file or directory exists
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# Handle specific file types directly (don't rewrite)
RewriteCond %{REQUEST_URI} \.(css|js|jpg|jpeg|png|gif|ico|pdf|svg|woff|woff2|ttf|eot)$ [NC]
RewriteRule ^ - [L]

# Handle API requests directly (don't rewrite)
RewriteCond %{REQUEST_URI} ^/adminlte/api/ [NC]
RewriteRule ^ - [L]

# Rewrite for PHP files (hiding .php extension)
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]

# Add trailing slash if needed (optional)
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_URI} !/$
# RewriteRule ^(.*)$ $1/ [L,R=301]

# Handle 404 errors
ErrorDocument 404 /adminlte/404.php

# Security headers
<IfModule mod_headers.c>
    # Protect against XSS attacks
    Header set X-XSS-Protection "1; mode=block"
    # Prevent MIME-sniffing
    Header set X-Content-Type-Options "nosniff"
    # Referrer policy
    Header set Referrer-Policy "same-origin"
</IfModule>

# PHP settings
<IfModule mod_php7.c>
    # Maximum execution time
    php_value max_execution_time 300
    # Maximum file upload size
    php_value upload_max_filesize 20M
    php_value post_max_size 21M
    # Memory limit
    php_value memory_limit 256M
</IfModule>

# Caching for static assets
<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 text/css "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType application/x-javascript "access plus 1 month"
</IfModule>

# Compression
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript application/x-javascript application/json
</IfModule>
