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.
www in the address
Trailing slash
Separate with a tab (pasting from a spreadsheet), a space, a comma or a semicolon. Old URLs must be on this site; new ones can point to another domain. Lines starting with # are skipped.
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.
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.
Questions.
What's the difference between 301 and 302?
How long should redirects stay after a move?
Redirect 301 or RewriteRule?
Why do I get “too many redirects” after adding the rules?
Can I redirect URLs with parameters, like ?id=15?
Do you send my URLs to your server?
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.