Binatomy
Serveur Web

Générateur .htaccess

Quickly build .htaccess rules for Apache: HTTPS, www redirect, compression, caching and more

Options

# --- 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

Questions Fréquentes

Everything you need to know about the .htaccess file

What is the .htaccess file and where does it go?

The .htaccess file is an Apache web server configuration file that lets you define directory-level rules: redirects, URL rewriting, security, caching and compression. Place it in your site's root folder (usually public_html or www); it affects that folder and its subfolders. The name starts with a dot and has no extension.

Does it work on Nginx?

No, the .htaccess file is specific to Apache (and compatible servers like LiteSpeed). Nginx does not use .htaccess: the same rules must be translated into the server configuration (server/location blocks in nginx.conf). If your host uses Nginx, this file will have no effect.

My site shows a 500 error after uploading the file, why?

A 500 error after editing .htaccess usually means a required module (mod_rewrite, mod_deflate, mod_expires) is not enabled on the server, or there is a syntax error. The rules here are wrapped in <IfModule> blocks precisely to avoid crashes if a module is missing. If it persists, remove rules one at a time to find the culprit and check with your host which modules are active. Always back up the previous file.

Qu'est-ce que le fichier htaccess ?

C'est le fichier de configuration qui donne des règles à un dossier sur Apache : redirections, réécriture d'adresses, cache, compression et restrictions. Il se place à la racine du site.

Fonctionne-t-il aussi sur Nginx ?

Non, htaccess est lu par Apache et les serveurs compatibles comme LiteSpeed. Sur Nginx, les mêmes règles doivent être réécrites dans la configuration du serveur, dans les blocs server et location.

Pourquoi le site renvoie-t-il une erreur 500 après modification ?

Le plus souvent, un module manque parmi mod_rewrite, mod_deflate et mod_expires, ou il y a une erreur de syntaxe. C'est pourquoi les règles générées sont placées dans des blocs IfModule.