.htaccess
Joomla! 6
Joomla! 5
Joomla! 4
Template
Intermediate
Force HTTPS, Block Sensitive Files and Harden Headers in .htaccess
Production Apache rules for Joomla: permanent HTTPS redirect, blocking .git/.env/backups and adding baseline security headers.
.htaccess
# Força HTTPS mantendo o domínio canônico
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Bloqueia acesso direto a arquivos sensíveis (.git, .env, backups SQL/ZIP)
RewriteRule ^\.git - [F,L]
<FilesMatch "(^\.env|composer\.(json|lock)|configuration\.php~|\.(sql|bak|log|ini))$">
Require all denied
</FilesMatch>
# Cabeçalhos mínimos de proteção
<IfModule mod_headers.c>
Header always set X-Content-Type-Options "nosniff"
Header always set Referrer-Policy "strict-origin-when-cross-origin"
Header always set Permissions-Policy "geolocation=(), microphone=(), camera=()"
</IfModule>
If Joomla core System - HTTP Headers plugin manages HSTS/CSP, avoid duplicating the same headers here.
Technical explanation and best practices
Place these directives before Joomla core SEF rewrite rules in your root .htaccess to guard .git, .env, SQL dumps and add protective HTTP response headers.