99 lines
5.3 KiB
ApacheConf
99 lines
5.3 KiB
ApacheConf
# Disable directory listing
|
|
Options -Indexes
|
|
|
|
# JPEG XL uploads (gym header/logo): older mime.types don't know the extension.
|
|
<IfModule mod_mime.c>
|
|
AddType image/jxl .jxl
|
|
</IfModule>
|
|
|
|
# Block direct HTTP access to sensitive files
|
|
<FilesMatch "^\.(env|env\..*|git.*|htaccess|htpasswd)$">
|
|
Require all denied
|
|
</FilesMatch>
|
|
<FilesMatch "^(composer\.(json|lock)|package(-lock)?\.json|yarn\.lock|\.gitignore|\.gitmodules|README\.md|CLAUDE\.md)$">
|
|
Require all denied
|
|
</FilesMatch>
|
|
<FilesMatch "\.sql$">
|
|
Require all denied
|
|
</FilesMatch>
|
|
|
|
# Belt-and-braces: block any dotfile path component (except /.well-known)
|
|
RewriteEngine On
|
|
RewriteRule "(^|/)\.(?!well-known)" - [F,L]
|
|
|
|
# Server-side trees: never reachable by URL (the repo root is the docroot here, and
|
|
# the dev tree serves it from /GitTea/repos/fitme3070.pt/).
|
|
RewriteRule ^(config|includes|database|logs|backups|templates|vendor)(/|$) - [F,L]
|
|
|
|
# A raiz web é o repositório inteiro, por isso fecha-se o que não é página:
|
|
# - parciais (_form.php e afins) só se incluem, nunca se pedem;
|
|
# - PHP soltos do platform-tools: só api/ e backups/ (auto-chamada com token)
|
|
# são endpoints; o resto é incluído pelas páginas de views/sysadmin/;
|
|
# - documentação (*.md) não é para servir.
|
|
RewriteRule "(^|/)_[^/]*\.php$" - [F,L]
|
|
RewriteRule "^shared/platform-tools/[^/]+\.php$" - [F,L]
|
|
RewriteRule "\.md$" - [F,L]
|
|
|
|
# ── Headers de segurança ─────────────────────────────────────────────────────
|
|
# script-src: 'self' (todo o JS próprio, incl. Bootstrap/jQuery/Summernote
|
|
# vendorizados desde 25/09) + 'unsafe-inline' (o site tem vários <script>
|
|
# inline — remover isso é reescrever cada um para nonce/hash, não cabe aqui)
|
|
# + cdn.jsdelivr.net (html2canvas em views/admin/horario/instagram.php,
|
|
# bootstrap-icons na página de erro). Já bloqueia o que importa: um
|
|
# <script src="https://outro-dominio/..."> injetado não carrega.
|
|
<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 X-Frame-Options "SAMEORIGIN"
|
|
Header always set Permissions-Policy "camera=(), microphone=(), geolocation=(), payment=(), usb=()"
|
|
Header always set Content-Security-Policy "frame-ancestors 'self'; base-uri 'self'; object-src 'none'; form-action 'self' https://forms.zohopublic.eu; script-src 'self' 'unsafe-inline' https://cdn.jsdelivr.net"
|
|
</IfModule>
|
|
|
|
# ── Canonical host: force HTTPS + strip www ───────────────────────────────────
|
|
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
|
|
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
|
|
RewriteCond %{HTTPS} off
|
|
RewriteCond %{HTTP:X-Forwarded-Proto} !https
|
|
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
|
|
|
|
# ── Let static files and backoffice pass through untouched ─────────────────────
|
|
RewriteRule ^views/ - [L]
|
|
RewriteRule ^uploads/ - [L]
|
|
RewriteRule ^site/assets/ - [L]
|
|
RewriteRule ^assets/ - [L]
|
|
|
|
# ── Friendly URLs ─────────────────────────────────────────────────────────────
|
|
# DEV ONLY: dev_login.php 404s sozinho se o platform-tools não tiver functions_dev.php.
|
|
RewriteCond %{REQUEST_FILENAME}.php -f
|
|
RewriteRule ^dev_login/?$ dev_login.php [L]
|
|
RewriteRule ^home/?$ site/index.php [L]
|
|
RewriteRule ^home/equipa/?$ site/equipa.php [L,QSA]
|
|
RewriteRule ^home/modalidades/?$ site/modalidades.php [L,QSA]
|
|
RewriteRule ^home/horario/?$ site/horario.php [L,QSA]
|
|
RewriteRule ^home/contactos/?$ site/contactos.php [L,QSA]
|
|
RewriteRule ^home/agendar/?$ site/agendar.php [L,QSA]
|
|
RewriteRule ^home/inscricao/?$ site/inscricao.php [L,QSA]
|
|
RewriteRule ^home/crossfit/?$ site/crossfit.php [L,QSA]
|
|
RewriteRule ^home/privacidade/?$ site/privacidade.php [L,QSA]
|
|
RewriteRule ^home/termos/?$ site/termos.php [L,QSA]
|
|
RewriteRule ^evento/([a-zA-Z0-9-]+)/?$ site/evento.php?slug=$1 [L,QSA]
|
|
# ── Ginásios: /<pasta>/ (código postal da zona, ex.: /3070/) ─────────────────
|
|
# Uma pasta por ginásio (Gestão → Ginásios); pastas desconhecidas ou por publicar
|
|
# dão 404 no PHP. Reais ficheiros/pastas têm prioridade.
|
|
RewriteCond %{REQUEST_FILENAME} !-f
|
|
RewriteCond %{REQUEST_FILENAME} !-d
|
|
RewriteRule ^([a-z0-9][a-z0-9-]{1,19})/?$ site/index.php?gym=$1 [L,QSA]
|
|
RewriteRule ^([a-z0-9][a-z0-9-]{1,19})/crossfit/?$ site/crossfit.php?gym=$1 [L,QSA]
|
|
RewriteRule ^([a-z0-9][a-z0-9-]{1,19})/(agendar|inscricao)/?$ site/$2.php?gym=$1 [L,QSA]
|
|
RewriteRule ^robots\.txt$ site/seo_files.php?f=robots [L]
|
|
RewriteRule ^sitemap\.xml$ site/seo_files.php?f=sitemap [L]
|
|
|
|
# Pass the Authorization header through to PHP
|
|
RewriteCond %{HTTP:Authorization} .
|
|
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
|
|
|
|
DirectoryIndex index.php
|
|
|
|
# Página 404 própria (a do Apache mostrava a versão do servidor).
|
|
ErrorDocument 404 /site/404.php
|