RewriteEngine On

# Remove .php extension from URLs
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

# Redirect .html URLs to clean URLs
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1? [NC,L,R=301]

# Redirect old .html URLs to new clean URLs
RewriteRule ^about/index\.html$ /about/ [R=301,L]
RewriteRule ^contact/index\.html$ /contact/ [R=301,L]
RewriteRule ^portfolio/index\.html$ /portfolio/ [R=301,L]
RewriteRule ^pricing/index\.html$ /pricing/ [R=301,L]
RewriteRule ^faqs/index\.html$ /faqs/ [R=301,L]
RewriteRule ^services/website-design\.html$ /services/website-design [R=301,L]
RewriteRule ^services/it-support\.html$ /services/it-support [R=301,L]
RewriteRule ^services/website-care\.html$ /services/website-care [R=301,L]
RewriteRule ^services/software-dev\.html$ /services/software-dev [R=301,L]
RewriteRule ^services/seo\.html$ /services/seo [R=301,L]
RewriteRule ^portfolio/case-template\.html$ /portfolio/case-template [R=301,L]
RewriteRule ^bitdefender/business\.html$ /bitdefender/business [R=301,L]
RewriteRule ^bitdefender/home\.html$ /bitdefender/home [R=301,L]

# Set default index files
DirectoryIndex index.php index.html

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

# Cache static assets
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/svg+xml "access plus 1 month"
    ExpiresByType image/webp "access plus 1 month"
</IfModule>

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