# Owlto Finance - Apache .htaccess Configuration
# For SEO optimization, SPA routing, and security

RewriteEngine On

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

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

# Redirect legacy .html URLs to clean routes (301 for SEO)
RewriteRule ^blog\.html$ /blog [R=301,L]
RewriteRule ^article1\.html$ /article/complete-guide [R=301,L]
RewriteRule ^article2\.html$ /article/comparison [R=301,L]
RewriteRule ^index\.html$ / [R=301,L]

# SPA fallback — serve index.html for client-side routes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.html [L]

DirectoryIndex index.html

Options -Indexes

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

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType image/svg+xml "access plus 1 year"
    ExpiresByType image/x-icon "access plus 1 year"
    ExpiresByType image/vnd.microsoft.icon "access plus 1 year"
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType text/javascript "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType text/html "access plus 0 seconds"
    ExpiresByType font/ttf "access plus 1 year"
    ExpiresByType font/woff "access plus 1 year"
    ExpiresByType font/woff2 "access plus 1 year"
</IfModule>

<IfModule mod_mime.c>
    AddType application/javascript js
    AddType text/css css
    AddType image/x-icon ico
    AddType image/svg+xml svg svgz
</IfModule>

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

ErrorDocument 404 /index.html

<FilesMatch "^\.">
    Order allow,deny
    Deny from all
</FilesMatch>

<Files .htaccess>
    Order allow,deny
    Deny from all
</Files>
