301 redirect generator

Ready-made rules for .htaccess and nginx: moving to https, one www version, trailing slashes and old pages moved in bulk. Everything runs in your browser.

Rules

www in the address

Trailing slash

Before going live, save a copy of your current .htaccess or nginx config and test the rules on a staging copy. Order matters: the first matching rule wins. Browsers cache a 301 for a long time, so test in a private window or with curl -I.

(02) — Details

When you need a 301 redirect

A 301 tells browsers and search engines that a page has moved for good and gives the new address. Over time the search engine swaps the old URL for the new one in its index and keeps counting the links that pointed to the old page. Without a redirect, old URLs return 404, visitors from bookmarks and other sites hit a dead end, and rankings have to be rebuilt from scratch.

Typical cases:

  • moving from http to https;
  • settling on one version of the address, with or without www;
  • a redesign or a new CMS that changed the URL structure;
  • a new domain;
  • a removed page that has a close replacement.

For temporary moves, such as a short promotion, there's 302. If the move is permanent, use 301.

How to use the generator

Enter your domain. In “Common rules”, tick what you need: https, www, trailing slash, clean URLs instead of index.php. Where possible, the rules get visitors to the main address in a single hop: http://www.example.com goes straight to https://example.com without a middle step.

In “URL list”, paste pairs of old and new URLs, for example two columns from a spreadsheet. The generator checks the list for:

  • old URLs on another domain, since a rule on this site won't fire for them;
  • duplicates and rules that an earlier line will catch first;
  • chains, where the new URL redirects again;
  • loops, where URLs point at each other in a circle;
  • URLs with parameters after the question mark, which need a different kind of rule.

Chains and loops

A chain is /a pointing to /b, which points to /c. The site still works, but every extra hop adds delay, and search crawlers only follow a limited number of steps. Chains usually pile up after several redesigns: the rules from the last move stay and new ones are added on top. The generator can point every old URL straight to its final destination.

A loop is URLs pointing at each other in a circle. The browser shows “Too many redirects” and the page doesn't open at all. The generator leaves such lines out of the rules.

Where the rules go

Apache. The .htaccess file in the site root. Put redirects at the top, before your CMS rules: in WordPress that's the # BEGIN WordPress block. mod_rewrite must be enabled, and most hosting providers have it on.

nginx. The server block of your site's config. After editing, run nginx -t to check the config, then reload nginx. Plain nginx ignores .htaccess. If nginx sits in front of Apache, as on many shared hosts, .htaccess usually works.

How not to break the site

  • Save a copy of the current .htaccess or config. If the site stops loading, restore the copy first and look for the mistake later.
  • Test on a staging copy if you have one.
  • Check every variant of the address: http and https, with and without www, with and without the slash. The quickest way is curl -I http://www.example.com/page, which shows the status code and the Location header.
  • Browsers remember a 301 and may not ask the server again. Test in a private window.
  • Check your CMS settings: WordPress and other CMSs have their own site address and redirects. If they disagree with .htaccess, you get a loop.
  • Don't send every removed page to the home page. Search engines treat that as an error. Point to the closest section, or return an honest 404.
(03) — Questions

Questions.

What's the difference between 301 and 302?
301 means moved permanently: the search engine replaces the old URL with the new one in its index. 302 is temporary, so the old URL stays indexed. For a new URL structure, https and the www choice, use 301.
How long should redirects stay after a move?
As long as people still arrive at the old URLs: from search, bookmarks, other sites, old newsletters. That's usually years. Redirect rules cost the server almost nothing, so there's no reason to remove them early.
Redirect 301 or RewriteRule?
RewriteRule is more precise: it fires only for the exact URL and can handle query strings. Redirect is simpler but matches everything that starts with the path, so /old/page goes to /new/page. If .htaccess already uses RewriteRule, for example for your CMS, use RewriteRule for redirects too.
Why do I get “too many redirects” after adding the rules?
Most often it's a loop: the .htaccess rule disagrees with the site address set in the CMS or with a redirect on the hosting side. The other common cause is a proxy or CDN in front of the server, so Apache always sees http. The generator has a separate checkbox for that case.
Can I redirect URLs with parameters, like ?id=15?
Yes. In list mode those URLs get their own rule: a RewriteRule with a query string condition for Apache, a $request_uri check for nginx. The rule fires only when the query string matches exactly, parameter order included.
Do you send my URLs to your server?
No. The rules are built in your browser and nothing is sent. You can confirm it in the Network tab of your browser's developer tools.
(04) — Studio

Moving to a new site and worried about rankings?

We'll map redirects for every old URL, check for chains and loops, set up the server and watch indexing after the move.