Account

What new tool do you want?

Developer Tools

.htaccess Redirect Generator

Generate Apache .htaccess 301 and 302 redirect rules from a list of old and new URLs, plus force-HTTPS and www rules.

How to use

  1. 1Enter one redirect per line: old path, a space, then the new URL.
  2. 2Choose the redirect type and extra rules, then paste the output into .htaccess.

Frequently asked questions

Should I use a 301 or 302 redirect?

Use 301 for permanent moves so search engines transfer rankings. Use 302 only for temporary changes.

Why does my redirect loop?

Usually a force-HTTPS or www rule conflicts with a host or proxy setting. Behind Cloudflare or a load balancer, check X-Forwarded-Proto instead of HTTPS.

Does .htaccess work on Nginx?

No. .htaccess is Apache-only (and LiteSpeed). Nginx uses return 301 rules in its server block.

Worked example: .htaccess Redirect Generator

Enter /old /new on one line and https://site.com/a https://site.com/b on another, and the tool strips the domain from the second line's source (since Redirect only needs a path, not a full URL) and emits # Page redirects\nRedirect 301 /old /new\nRedirect 301 /a https://site.com/b. Turn on Force HTTPS and Remove www with no page redirects entered, and it instead produces a RewriteEngine On block followed by two separate RewriteCond/RewriteRule pairs — one checking %{HTTPS} off to force the HTTPS redirect, another checking the host starts with www. to strip it. The two features generate structurally different Apache directives (simple Redirect lines vs. mod_rewrite conditions) because they're solving different problems: static path redirects don't need conditional logic, but protocol and subdomain rewriting do.

Why forcing HTTPS and stripping www can create a redirect loop

Both rules check a condition and redirect if it's not met — HTTPS off → redirect to HTTPS, host starts with www → redirect to the bare domain. Behind a reverse proxy, CDN or load balancer (Cloudflare, an AWS ALB) that terminates TLS before traffic reaches your Apache server, %{HTTPS} can report "off" even though the original visitor connection really was HTTPS — causing Apache to "helpfully" redirect to HTTPS again, which the proxy strips again, forever. The FAQ's fix is the standard one: check X-Forwarded-Proto instead of %{HTTPS} when a proxy sits in front, since that header preserves what the original client actually used.

Why this only helps if your host actually runs Apache

.htaccess directives are read and applied exclusively by Apache (and the Apache-compatible LiteSpeed) — the file does nothing at all on Nginx, which has no equivalent per-directory config file mechanism and instead expects redirect logic written directly into its server block as return 301 statements. If your production stack sits behind Nginx, a CDN edge config, or a platform like Vercel/Netlify, this generated file needs to be translated into that platform's own redirect syntax — pasting .htaccess rules into an Nginx config simply won't be read at all.

A line must be exactly two pieces, and www rules always use https

Redirect type opens on 301 permanent. Blank lines and lines that start with a hash are skipped. A line that is not exactly an old path and a new address, separated by space, stops with the line number and asks for old-path and new-url. A full address used as the old path has the site name stripped, and a path without a leading slash gets one. Force HTTPS starts off, and www opens on leave as is. Force www and remove www write a destination that starts with https even when Force HTTPS is off. An empty box with both extras left off produces no rules. The placeholder shows a short path pair and a blog path that points at a full address.

Related tools

More: Developer Tools