Productivity and Utilities

.htaccess Redirect Generator

Build Apache redirect rules from a simple list of old and new addresses.

Write the old path, then the new path or full URL, such as /old-page /new-page. Add a code at the end to change it for that line, or write /gone 410 for a page that was removed. Lines starting with # are notes.

Used for lines with no code of their own.

Below means /blog also catches /blog/post-1 and keeps the rest of the path.

Site wide rules (optional)

Without https:// or www. Used only for the www rules.

Every address on it goes to the same path on the new domain.

These rules are for Apache servers (and compatible ones) with mod_rewrite turned on and AllowOverride permitting .htaccess. A mistake can take a whole site offline, so keep a copy of your current file and test on a test copy of the site first. Other servers, such as Nginx, use a different syntax.

Next step

How to use the .htaccess redirect generator

  1. Write your page redirects, one per line: the old path, then the new path or full address, such as /old-page /new-page.
  2. Choose the redirect type and whether a rule matches the exact path or the path and everything below it.
  3. Optionally turn on https, choose how to handle www, and set a domain move.
  4. Copy the rules or download the file, then test it on a copy of the site.

What the rules mean

Every rule uses Apache's mod_rewrite, so they work together in the order written. A permanent redirect (301 or 308) tells browsers the page has moved for good, and a temporary one (302, 303 or 307) says it may come back. A line that ends in 410 says the page is gone, and the server answers with that status and no destination.

Paths are matched without the leading slash, and characters that mean something in a pattern, such as a dot or a plus sign, are escaped, so /a.b matches only /a.b. A rule with a question mark, such as /shop?id=5, adds a condition on the query string and drops the query from the destination. The "path and below" choice also keeps the rest of the path, so /blog/post-1 goes to /articles/post-1.

Checks before a rule is written

The tool refuses lines that could break a file or be unsafe: an old path that does not start with a slash, spaces or quotes, a destination that is not a full web address or a path, and a destination containing a dollar sign or a percent brace, which Apache would read as a variable. Each problem is listed with its line number.

Domains for the www and move rules must look like real host names. Related tools include the robots.txt generator, the meta tag generator and the URL encoder and decoder for encoding awkward characters.

Testing and limits

These rules suit Apache servers, and compatible ones, with mod_rewrite on and .htaccess files allowed. Servers such as Nginx use another syntax. A mistake in .htaccess can bring a site down or create a loop, so keep a copy of the current file and test on a copy of the site. After the change, check a handful of old addresses in a browser and look at the status code. Nothing you enter leaves this page.

Assumptions and limits

  • The output is for Apache with mod_rewrite. Other servers need other syntax.
  • Rules run in the order written, with the domain move first, then page rules, then https and www.
  • Query string rules use the QSD flag, which needs Apache 2.4.
  • The tool cannot see your server, so test every change.

Formulas reviewed October 10, 2026. See the calculation methodology for how SumPanda rounds, tests and sources its formulas.

Frequently asked questions

How do I write a 301 redirect in .htaccess?

Add a RewriteRule with the R=301 flag, such as RewriteRule ^old-page/?$ /new-page [R=301,L]. This tool writes it for you from a line like /old-page /new-page.

How do I redirect http to https?

Tick the https option. The tool adds a condition that checks the connection is not secure and redirects to the https version of the same address.

How do I redirect a whole domain to another?

Fill in the old and new domain. Every address on the old domain goes to the same path on the new one.

What is a 410 line?

It tells visitors a page is gone for good. Write the old path followed by 410 and no destination.

Why test on a copy of the site first?

A faulty rule can cause redirect loops or errors for every visitor, and a permanent redirect can be remembered by browsers for a long time.