.htaccess Redirect Generator – 301, HTTPS, www
NOUVEAU.htaccess redirect generator for Apache: force HTTPS, www or non-www, trailing slashes, 301/302 redirects and clean URLs as commented mod_rewrite rules.
Fonctionne à 100 % dans votre navigateur — vos données ne sont jamais envoyées ni stockées sur nos serveurs.
Cet outil n'est pas encore entièrement traduit : une partie du texte est encore en anglais. L'outil lui-même fonctionne de la même façon dans toutes les langues.
- info: Browsers cache 301 redirects hard. Test with 302 first, then switch to 301 when the rules are correct.
- info: Rule order matters: Apache runs rules top to bottom and [L] stops the current pass. Keep specific redirects above the site-wide HTTPS/www rules, and internal rewrites last.
- info: Behind a load balancer or Cloudflare, %{HTTPS} may always be "off". Use RewriteCond %{HTTP:X-Forwarded-Proto} !https instead to avoid a redirect loop.
Generated .htaccess.htaccess
# .htaccess generated by UsefulTools.dev
# Place it in the document root. Requires mod_rewrite (AllowOverride FileInfo or All).
RewriteEngine On
# 1. Single redirects (most specific first, before the site-wide rules)
RewriteRule ^old-page/?$ /new-page [R=301,L]
RewriteRule ^blog/2019/hello/?$ /blog/hello-world [R=301,L]
RewriteCond %{QUERY_STRING} ^id=42$
RewriteRule ^product\.php/?$ /products/blue-widget? [R=301,L]
RewriteRule ^promo/?$ https://shop.example.com/sale [R=302,L]
# 2. Force HTTPS and non-www in a single 301 hop
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
# Custom 404 page
ErrorDocument 404 /404.html
Exemples rapides
Des entrées typiques et les résultats produits par cet outil.
Présentation
Apache reads per-directory rules from a .htaccess file, and most redirects there are written with mod_rewrite. This .htaccess redirect generator writes those rules for you: force HTTPS, redirect www to non-www (or the other way) in a single 301 hop, add or remove trailing slashes, serve /page from page.html, set a custom 404 page and add any number of single 301 or 302 redirects from an old path to a new one.
Rules are emitted in a safe order with a comment on each block, specific redirects first and internal rewrites last. The generator warns about redirect loops, chains, duplicate sources and setups that loop behind a proxy. It runs entirely in your browser.
Pourquoi utiliser cet outil ?
- No more hand-escaping mod_rewrite regex
- HTTPS and www handled in one redirect, not two
- Old URLs with query strings redirected correctly
- Warnings for loops, chains and rule order
- Commented output you can review before deploying
Fonctionnalités
Force HTTPS
Redirects every plain-HTTP request to HTTPS, combined with the www rule when both are on.
www or non-www
Pick one canonical host; the other one gets a permanent redirect.
Bulk 301 / 302
Paste "old new [code]" lines; full old URLs and query strings are supported.
Clean URLs
Remove .html extensions and add or remove trailing slashes.
Order warnings
Flags loops, redirect chains, duplicate sources and risky combinations.
Custom 404
Adds an ErrorDocument line and warns if you use a full URL.
Mode d'emploi
Pick site-wide rules
Tick Force HTTPS, choose the www handling and trailing slash mode.
List redirects
Enter one "old new" pair per line, optionally followed by 301 or 302.
Read the warnings
Fix errors and chains shown above the output.
Download and test
Download .htaccess, upload it to the document root and test with curl -I.