Binatomy
Web Server

Generatore .htaccess

Crea rapidamente le regole del file .htaccess per Apache: HTTPS, redirect www, compressione, cache e altro

Opzioni

# --- Rewrite rules ---
<IfModule mod_rewrite.c>
  RewriteEngine On

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

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

# --- Gzip compression ---
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
  AddOutputFilterByType DEFLATE application/javascript application/x-javascript application/json
  AddOutputFilterByType DEFLATE application/xml application/rss+xml image/svg+xml
</IfModule>

# --- Browser caching ---
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/jpg "access plus 1 year"
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/webp "access plus 1 year"
  ExpiresByType image/svg+xml "access plus 1 year"
  ExpiresByType image/x-icon "access plus 1 year"
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"
  ExpiresByType text/html "access plus 1 day"
</IfModule>
FAQ

Domande Frequenti

Tutto quello che devi sapere sul file .htaccess

Cos'è il file .htaccess e dove va messo?

Il file .htaccess è un file di configurazione del server web Apache che permette di definire regole a livello di directory: redirect, riscrittura URL, sicurezza, cache e compressione. Va posizionato nella cartella radice del tuo sito (di solito public_html o www) e ha effetto su quella cartella e le sue sottocartelle. Il nome inizia con un punto e non ha estensione.

Funziona su Nginx?

No, il file .htaccess è specifico di Apache (e server compatibili come LiteSpeed). Nginx non usa .htaccess: le stesse regole vanno tradotte nella configurazione del server (blocchi server/location in nginx.conf). Se il tuo hosting usa Nginx, questo file non avrà effetto.

Il mio sito dà errore 500 dopo aver caricato il file, perché?

Un errore 500 dopo la modifica di .htaccess di solito significa che un modulo richiesto (mod_rewrite, mod_deflate, mod_expires) non è abilitato sul server, oppure c'è un errore di sintassi. Le regole qui sono racchiuse in blocchi <IfModule> proprio per evitare crash se un modulo manca. Se persiste, rimuovi le regole una alla volta per individuare quella problematica e verifica con il tuo hosting quali moduli sono attivi. Fai sempre un backup del file precedente.

Was ist die Datei htaccess?

Es ist die Konfigurationsdatei, die auf Apache Regeln für einen einzelnen Ordner setzt: Umleitungen, Umschreiben von Adressen, Zwischenspeicher, Komprimierung und Sperren. Sie gehört in den Stammordner der Website.

Funktioniert sie auch auf Nginx?

Nein, htaccess liest Apache und verträgliche Server wie LiteSpeed. Auf Nginx müssen dieselben Regeln in die Serverkonfiguration übertragen werden, in die Blöcke server und location.

Warum gibt die Seite nach der Änderung einen Fehler 500?

Meist fehlt eines der Module mod_rewrite, mod_deflate oder mod_expires, oder es steckt ein Tippfehler drin. Deshalb stehen die erzeugten Regeln in Blöcken IfModule, die sie abschalten, wenn das Modul fehlt.