Utilia

.htaccess Redirect Generator

Generate 301 and 302 redirects for .htaccess or Nginx, force HTTPS and www, move a domain and fix trailing slashes, with checks for loops and chains.

Server
Redirect type
Canonical address
Trailing slash
Move the whole domain

Back up your current configuration first, and test with 302 before switching to 301: browsers cache permanent redirects.

Checks

How to use the .htaccess redirect generator

  1. Choose your Server: Apache (.htaccess) or Nginx, then the Redirect type: 301 – permanent or 302 – temporary.
  2. In Page redirects, write one redirect per line: the old path, a space, then the new URL, for example /old-page.html /new-page/. A tab, a comma or -> also work, and you can paste full old URLs or existing Redirect 301 /a /b lines.
  3. Optionally enter Your domain (for example example.com) so that page redirects point straight to the final address.
  4. Under Canonical address, tick Force HTTPS and pick Force www, Remove www or Leave www as is. Under Trailing slash, choose whether to add or remove it.
  5. If the whole site moved, fill in Move the whole domain with the Old domain and the New address, and keep Keep the path ticked so every page lands on its equivalent.
  6. Read the Checks, then Copy or Download the rules. Use Load an example to see a complete configuration.

How the generated rules work

For Apache, the tool writes mod_rewrite rules, starting with a single RewriteEngine On. Each page becomes a RewriteRule whose pattern starts with ^/?, so it works both in a .htaccess file (where the leading slash is removed) and in a <VirtualHost> block. Dots, brackets, plus signs and other regular-expression characters in your paths are escaped, and a space becomes \x20. In the new URL, $ and % are escaped because Apache would read them as back-references, and the NE flag stops Apache from encoding the URL a second time.

A RewriteRule never sees the query string. When an old address contains one, such as /product.php?id=42, the tool adds a RewriteCond %{QUERY_STRING} ^id=42$ line and the QSD flag, so the old parameters are dropped instead of being copied to the new page.

The rules are ordered to avoid needless hops: domain move first, then page redirects, then the trailing slash, then HTTPS and www. HTTPS and www are handled by one rule, so http://www.example.com goes to https://example.com in a single redirect. When your domain is known, page and slash redirects already point to the final HTTPS address.

For Nginx, HTTPS, www and domain moves become separate server blocks with return 301, and page redirects become rewrite lines to paste inside your main server block. They run before location matching, so they also win over the trailing-slash rule. A ? at the end of a target stops Nginx from appending the old query string when it should not.

Checks performed

  • A page that redirects to itself, or two pages that redirect to each other (a loop that ends in “too many redirects”).
  • Chains such as A → B → C: point A straight to C, because every extra hop slows visitors down and wastes crawl budget.
  • The same old address listed twice, where only the first rule would apply.
  • A target that is neither an absolute URL nor a path starting with /, or an http:// or wrong-www target on your own domain.
  • A trailing-slash setting that would redirect a target again or send it back to its source.

Frequently asked questions

Should I use 301 or 302?

Use 301 when the move is permanent: search engines transfer the old page’s signals to the new one and update their index. Use 302 for temporary changes such as maintenance or a short campaign. Browsers cache 301 redirects, so test with 302 first.

Where do I put the .htaccess file?

In the root folder of the site (often public_html or www), next to index.php or index.html. The download is named htaccess.txt; rename it to .htaccess, or paste the rules at the top of your existing file. Keep a backup of the original.

Why use RewriteRule instead of Redirect 301?

Redirect lines come from mod_alias and run in a different phase from RewriteRule. Mixing both in one file makes the order hard to predict. Using only mod_rewrite keeps every rule in one predictable sequence and allows query strings to be matched.

My site shows "too many redirects" after forcing HTTPS. Why?

Behind a load balancer, CDN or proxy that terminates HTTPS, Apache sees every request as plain HTTP, so %{HTTPS} is always off. In that case test the forwarded header instead, for example RewriteCond %{HTTP:X-Forwarded-Proto} !https, or enable the redirect in the CDN.

Does this tool change my server?

No. It only generates text in your browser. Nothing is sent anywhere, and you stay in control of where and how the rules are installed.