RevealTheme logo

Générateur de fragments .htaccess

Générez des règles .htaccess courantes : forcer le HTTPS, rediriger www, définir des en-têtes de cache, activer Gzip.

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

Comment utiliser cet outil

  1. 1

    Open the dropdown and choose the rule you need (for example, Force HTTPS or Gzip compression).

  2. 2

    Read the generated snippet shown in the code box below the dropdown.

  3. 3

    Select the text and copy it, then paste it into your site's .htaccess file.

  4. 4

    Switch the dropdown to a different rule to view another snippet — combine several by pasting them one after another.

Qu'est-ce que le générateur de fragments .htaccess ?

.htaccess est le fichier de configuration par répertoire d'Apache. Il contrôle la réécriture d'URL, les redirections, la mise en cache, la compression et les en-têtes de sécurité. Hostinger et la plupart des hébergements mutualisés utilisent Apache (ou LiteSpeed, qui est compatible). Ces fragments couvrent les besoins les plus courants.

Cas d'usage courants

  • Forcing every visitor onto HTTPS after installing an SSL certificate on a shared Apache or LiteSpeed host.

  • Canonicalizing a domain to either the www or non-www version with a 301 redirect to consolidate SEO signals.

  • Adding a one-year browser cache to static assets so repeat visitors load CSS, JS, and modern image formats from cache.

  • Turning on Gzip compression for text responses to cut transfer size and improve page load time.

  • Hiding the contents of a folder that has no index file by disabling Apache's automatic directory listing.

  • Blocking PHP execution inside a public uploads directory so an attacker can't run a script they managed to upload.

Questions fréquentes

.htaccess fonctionne-t-il sur Nginx ?
Non : Nginx utilise sa propre syntaxe de configuration. Ces fragments sont réservés à Apache/LiteSpeed.
Où placer le fichier .htaccess ?
À la racine de votre site (à côté de index.html). Les règles s'appliquent à ce répertoire et à tous ses sous-répertoires.

Outils connexes