Skip to main content
Premier SEO Services

Developer tools

.htaccess Redirect Generator

Generate Apache .htaccess rules for page, folder and domain redirects plus HTTPS, www and trailing-slash rules, ordered so every old address reaches its new one in a single redirect.

  • Runs in your browser
  • Free, no sign-up
  • Unlimited use
  • Updated 30 September 2026

.htaccess Redirect Generator

Set the options, then copy or download the result

  • Rules are for Apache (and LiteSpeed). Nginx, IIS and most managed hosts with their own redirect settings need a different format.

How to use the .htaccess redirect generator

  1. 1Enter Your domain and choose the site-wide rules: Redirect HTTP to HTTPS, www (remove or add), Trailing slash and the /index.html option.
  2. 2Under Redirects, choose each row's type (Page, Folder, Whole domain or Removed (410 Gone)), its Status, the Old path and the New path or URL. Press Add redirect for more rows.
  3. 3Read any warnings above the code, then press Copy or Download (saved as htaccess.txt; rename it to .htaccess).
  4. 4Press Test these rules in the .htaccess tester to try URLs against the rules before uploading.

Example

Input
Domain example.com, Redirect HTTP to HTTPS, Remove www, and a 301 from /old-page/ to /new-page/
Output
RewriteEngine On

# Individual redirects (first, and straight to the final address, so there is only one hop)
RewriteRule ^old-page/?$ https://example.com/new-page/ [R=301,L,NE]

# Everything else: send to the canonical address in one redirect (https://example.com)
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L,NE]

http://www.example.com/old-page/ goes to https://example.com/new-page/ in one redirect instead of two.

Redirect vs RewriteRule

Apache has two ways to redirect. mod_alias (Redirect 301 /old /new, RedirectMatch) is simple but can only look at the path. mod_rewrite (RewriteCond + RewriteRule) can also test the host, HTTPS, query string or whether a file exists, which the HTTPS and www rules need.

The generator uses mod_rewrite throughout, because mixing the two in one file is a classic source of bugs: Apache runs all mod_rewrite rules first and mod_alias after, regardless of their order in the file. If your existing .htaccess has Redirect lines, convert them or keep them in mind when testing.

Page, folder and domain redirects

  • Page redirects one path. /old-page/ matches with or without its trailing slash. A query string in the old path (/product.php?id=5) adds a RewriteCond %{QUERY_STRING} and the QSD flag, so the old parameters aren't carried over.
  • Folder redirects a directory and everything in it, keeping the rest of the path: /blog/2026/post → /news/2026/post.
  • Whole domain sends every URL on an old domain to the same path on the new one, matching with or without www. Use it when the old domain points at the same hosting.
  • Removed (410 Gone) tells search engines a page is permanently gone, which drops it from results faster than a 404.

Use 301 (or 308) for permanent moves and 302 (or 307) for temporary ones. 307 and 308 also keep POST requests as POST. See 301 vs 302 redirects for when each fits.

HTTPS and www rules

One combined rule handles both: if the request isn't HTTPS or the host isn't the canonical one, it redirects to https:// + canonical host + the original path, so http://www.example.com/page needs one hop, not two. The NE flag stops Apache from escaping characters in the path a second time.

If your site is behind Cloudflare or a load balancer that terminates TLS, %{HTTPS} is always off at your server and this rule loops forever. In that case use the proxy's "Always use HTTPS" setting, or replace the condition with RewriteCond %{HTTP:X-Forwarded-Proto} !https.

Avoiding chains and loops

A chain is one redirect leading to another (http://www → https://www → https:// → new page). Each hop adds a round trip, and search engines stop following after several. The generator avoids them in two ways: individual redirects come first and point straight at the final https:// canonical address, and the HTTPS and www fixes share a single rule.

A loop redirects back to itself. The generator warns when a page redirects to its own path. The trailing-slash rules skip real files (!-f), so /style.css never becomes /style.css/, and the /index.html rule only acts on what the browser actually requested (THE_REQUEST), so it can't fight with internal rewrites.

Testing your rules

Before uploading, paste the code into the .htaccess tester (the link under the code does it for you) and try your old URLs: it shows which line matches and where each request ends up. After uploading, keep a copy of the old file, then check real responses with the redirect checker, which shows every hop and status code. A 500 Internal Server Error straight after uploading usually means a typo or that mod_rewrite isn't enabled; restore the old file and check the server's error log.

Is anything I enter stored?

This tool runs entirely in your browser. Your text is not uploaded to our servers.

Sources

Questions about the .htaccess redirect generator

Where do I put the .htaccess file?

In your site's document root, the folder that contains your home page (often public_html or www). If a file is already there, add the rules near the top, above any CMS rules such as WordPress's block.

Why isn't my redirect working?

The usual causes: mod_rewrite isn't enabled or AllowOverride doesn't allow .htaccess files, an earlier rule with [L] matches first, the browser cached an old 301, or the host ignores .htaccess (Nginx). Test in a private window and in the .htaccess tester.

Does Nginx use .htaccess?

No. Nginx reads redirects from its server configuration, for example location = /old-page/ { return 301 https://example.com/new-page/; }. The rules here work on Apache and LiteSpeed servers.

Learn more

Last updated 30 September 2026Maintained by Premier SEO Services

Report a problem