<?php
/**
 * .htaccess configuration for Apache
 * Enables URL rewriting for clean URLs
 */
?>
<IfModule mod_rewrite.c>
    RewriteEngine On
    
    # Set base directory
    RewriteBase /ChatBud-PHP/public/
    
    # Remove trailing slash
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]
    
    # Route all requests to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.php [QSA,L]
    
    # Security headers
    <FilesMatch "\.(gif|jpg|jpeg|png|css|js|svg|woff|woff2|ttf|eot)$">
        Header set Cache-Control "max-age=31536000, public"
        Header set Expires "Wed, 17 Aug 2027 01:06:23 GMT"
    </FilesMatch>
</IfModule>

# Disable directory listing
Options -Indexes

# Block access to sensitive files
<FilesMatch "^(\.env|\.gitignore|composer\.json|composer\.lock)">
    Order allow,deny
    Deny from all
</FilesMatch>

# Compress text files
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/x-javascript application/xml+rss text/x-js
</IfModule>

# Prevent access to source files
<FilesMatch "\.php$">
    Deny from all
</FilesMatch>

<FilesMatch "index\.php$">
    Allow from all
</FilesMatch>
