# 301 Redirect Generator Guide: 301 vs 302, and Redirect Code for Apache, Nginx, Next.js and Cloudflare

> Use a free 301 redirect generator for .htaccess, Nginx, Next.js and Cloudflare, learn 301 vs 302 vs 308, and avoid redirect chains and loops in migrations.

Canonical: https://abacklaunch.com/blog/301-redirect-guide
Last updated: 2026-11-19

By Devvrat Hans, Founder. 10 min read. Published 2026-11-19.

A 301 redirect generator turns a list of old and new URLs into the permanent redirect rules your server understands, so you do not have to remember the syntax for each platform. Paste one old URL and one new URL per line into the free [301 redirect generator](https://abacklaunch.com/tools/redirect-generator), pick Apache.htaccess, Nginx, Next.js, Vercel, Netlify, Cloudflare or Express, and copy the rules. Then test a few with a redirect checker before you ship.

The rules are the easy part. The decisions around them are where sites lose traffic: using a 302 when you meant a 301, sending every old page to the home page, or stacking redirects into chains that crawlers stop following. This guide covers which status code to use, working code for each major server, how to test the result with the [redirect checker](https://abacklaunch.com/tools/redirect-checker), and a migration checklist that keeps your rankings intact.

## 301 vs 302 vs 307 vs 308

All four tell the browser to go somewhere else. They differ on two questions: is the move permanent, and may the browser change the request method (turning a form POST into a GET)?

| Code | Meaning | Permanent? | Keeps request method? | Use it for | |
| 301 | Moved Permanently | Yes | Not guaranteed (browsers may switch POST to GET) | Pages that moved for good: renamed URLs, merged pages, domain moves | |
| 302 | Found | No | Not guaranteed | Short-term moves: a sale page, maintenance, A/B tests | |
| 307 | Temporary Redirect | No | Yes | Temporary moves where a POST must stay a POST | |
| 308 | Permanent Redirect | Yes | Yes | Permanent moves, including API endpoints and form targets | |

### Which one does SEO need?

For search, the split that matters is permanent versus temporary. Google treats 301 and 308 as a strong signal that the new URL should be indexed in place of the old one, and moves the old URL's signals to it. A 302 or 307 tells Google the old URL is coming back, so it tends to keep the old URL in the index. If a temporary redirect stays in place for a long time, Google may eventually treat it as permanent, but do not rely on that: if the move is permanent, say so.

Between 301 and 308, search engines make no practical difference for ordinary pages. 301 is the safe, universally understood choice; 308 is right when the method must be preserved. One thing to know: Next.js and Vercel use 308 when you set permanent to true. That is fine for SEO. See our glossary entry on the [301 redirect](https://abacklaunch.com/glossary/redirect-301) for the short version.

### Meta refresh and JavaScript redirects

Google can follow an instant meta refresh and a JavaScript redirect, but they are slower, depend on the page being fetched or rendered, and other crawlers handle them less reliably. Use a server-side 301 whenever you control the server. Keep client-side redirects for hosts that give you no other option.

## When to use a 301 redirect

- **You renamed a URL.** /features became /product. Redirect old to new.
- **You merged pages.** Three thin posts became one guide. Redirect each old post to the guide.
- **You moved to https or picked a host.** http, https, www and non-www should all end on one version.
- **You moved domains.** Every old URL redirects to the same path on the new domain.
- **You deleted a page that has links or traffic.** Redirect it to the closest equivalent page. If nothing is equivalent, a 404 or 410 is more honest than a redirect to the home page, which Google may treat as a soft 404 anyway.

When the old URL still has to work for visitors (tracking parameters, filtered views), you want a canonical tag instead of a redirect. Our [canonical tag guide](https://abacklaunch.com/blog/canonical-tag-guide) explains the difference.

## 301 redirect code for each platform

The examples below are what you would write by hand. The redirect generator produces the same kind of rules from a list, which is faster and avoids typos once you have more than a few URLs.

### Apache.htaccess redirect

For one-to-one page moves, Apache's Redirect directive is the simplest form:

```
Redirect 301 /old-pricing /pricing
Redirect 301 /blog/launch-tips /blog/launch-checklist
```

Watch out: Redirect matches by prefix, so the first line would also send /old-pricing/faq to /pricing/faq. For an exact match, use RedirectMatch with anchors:

```
RedirectMatch 301 ^/old-pricing$ /pricing
```

For patterns, use mod_rewrite. These are the rewrite rules people most often need:

```
RewriteEngine On

# Force https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

# Move a whole folder
RewriteRule ^blog/(.*)$ /articles/$1 [R=301,L]

# Move to a new domain, keeping the path
RewriteCond %{HTTP_HOST} ^(www\.)?old-domain\.com$ [NC]
RewriteRule ^(.*)$ https://new-domain.com/$1 [R=301,L]
```

R=301 sets the status code (without it, mod_rewrite sends a 302) and L stops processing further rules for that request. The generator's.htaccess output uses the Redirect directive, one line per URL pair, so for folder and domain patterns like the ones above, write the RewriteRule yourself.

### Nginx redirect

In Nginx, return is the fastest and clearest way to redirect. Put exact matches in their own location block:

```
location = /old-pricing {
return 301 /pricing;
}

# Move a whole folder
location /blog/ {
rewrite ^/blog/(.*)$ /articles/$1 permanent;
}

# Send http and www to one https host
server {
listen 80;
server_name example.com www.example.com;
return 301 https://example.com$request_uri;
}
```

In a rewrite line, the permanent flag sends a 301 and the redirect flag sends a 302. Reload Nginx after editing, and run nginx with the test flag first to catch syntax errors before they take the site down.

### Next.js redirects in next.config

Next.js reads redirects from an async function in next.config.js (or next.config.ts):

```
module.exports = {
async redirects() {
return [
{ source: "/old-pricing", destination: "/pricing", permanent: true },
{ source: "/blog/:slug", destination: "/articles/:slug", permanent: true },
{ source: "/docs/:path*", destination: "https://docs.example.com/:path*", permanent: true },
];
},
};
```

permanent: true sends a 308 and permanent: false sends a 307. If you need a literal 301 for an old client, Next.js accepts statusCode: 301 in place of permanent. The:slug and:path* parameters let one rule cover many URLs. For thousands of individual redirects, a lookup in middleware scales better than a huge list in the config.

### Cloudflare redirects

Cloudflare gives you three options, depending on how your site is hosted:

- **A _redirects file** for sites on Cloudflare Pages or Workers static assets. One rule per line: the source, the destination and the status code.
- **Single Redirects** (Redirect Rules in the dashboard) for pattern rules on any proxied domain, such as forcing one host.
- **Bulk Redirects** for large lists of one-to-one URL redirects managed as a list in the dashboard.

```
/old-pricing /pricing 301
/blog/launch-tips /blog/launch-checklist 301
/docs/* https://docs.example.com/:splat 301
```

The redirect generator's Cloudflare and Netlify output uses this _redirects format. Cloudflare caps how many rules a _redirects file can hold, so check the current limit in its documentation if your map is large, and move very large maps to Bulk Redirects.

## Generate redirect rules from a list

Writing ten redirects by hand is fine. Writing three hundred for a migration is where typos creep in. The [URL redirect generator](https://abacklaunch.com/tools/redirect-generator) does this in three steps:

1. **Paste URL pairs.** Old URL and new URL on each line, separated by a space, comma or tab. Paths and full URLs both work.
2. **Pick the status and platform.** 301 or 308, and Apache.htaccess, Nginx, Next.js, Vercel (vercel.json), Netlify (_redirects), Cloudflare (_redirects) or Express.
3. **Copy the rules** into your config file.

When old and new are on the same site, the rules use paths; when the new URL is on another domain, the full URL is kept. Everything runs in your browser, so your URL list is not uploaded anywhere. Next.js and Vercel output always uses permanent: true, which those platforms serve as 308.

## Test every redirect

A redirect that looks right in a config file can still be wrong in production: another rule fires first, a CDN caches an old response, or the destination itself redirects. Paste a few old URLs into the [redirect checker](https://abacklaunch.com/tools/redirect-checker). It follows every hop (up to 10), shows the status code of each, and the final page. You want exactly one hop, a 301 or 308, landing on a page that returns 200.

Test these URLs in particular:

- the http:// and www versions of your home page
- the old URLs that have the most backlinks or traffic
- a URL with a query string and one with a trailing slash
- a URL that should not redirect at all, to catch rules that match too broadly

## Avoid redirect chains and loops

A [redirect chain](https://abacklaunch.com/glossary/redirect-chain) is a URL that redirects to a URL that redirects again. The classic one is http://www.example.com/old going to https://www.example.com/old, then to https://example.com/old, then to https://example.com/new. Each hop adds a round trip for visitors, and Googlebot follows only up to 10 hops before reporting a redirect error. Chains usually grow by accident: a page moves twice, and the first redirect still points at the middle URL.

How to fix and prevent them:

- **Point every old URL straight at the final destination.** When a page moves a second time, update the earlier redirects too.
- **Put host and protocol redirects in one rule.** The Nginx server block above sends http and www to the final https host in a single hop.
- **Update internal links.** Links on your own site should point at the final URL, not rely on a redirect. The [broken link checker](https://abacklaunch.com/tools/broken-link-checker) flags links that go through needless redirects.

A redirect loop is a chain that comes back to where it started: /a redirects to /b and /b redirects to /a, or an https rule fights a CDN setting that forces http. Browsers give up with a "too many redirects" error. The redirect checker shows the hop where the loop closes.

## A redirect checklist for site migrations

1. **List every old URL.** Export them from your current sitemap with the [sitemap URL extractor](https://abacklaunch.com/tools/sitemap-url-extractor), and add any URLs with backlinks or traffic that the sitemap misses.
2. **Map each one to its closest new page.** One to one where possible. Do not send everything to the home page.
3. **Compare old and new.** The [sitemap compare tool](https://abacklaunch.com/tools/sitemap-compare) shows which URLs disappear in the new version; each removed URL with traffic needs a 301.
4. **Generate and deploy the rules** with the redirect generator.
5. **Test a sample** with the redirect checker, including the edge cases above.
6. **Update everything that points at old URLs:** internal links, canonical tags, hreflang and the sitemap, which should list only final URLs. Our [XML sitemap guide](https://abacklaunch.com/blog/xml-sitemap-guide) covers the sitemap side.
7. **For a domain move, use Search Console's Change of Address tool** after the redirects are live, and keep both properties verified.
8. **Keep the redirects.** Google recommends keeping them for at least a year; if the old URLs have backlinks, keep them for good.

Google's own guide to [redirects and Google Search](https://developers.google.com/search/docs/crawling-indexing/301-redirects) is the reference if you need the detail on each method. When your list is ready, build the rules with the free [301 redirect generator](https://abacklaunch.com/tools/redirect-generator) and check the result before you announce the move.

## FAQ

### What is the difference between a 301 and a 302 redirect?

A 301 says the page moved permanently, so search engines index the new URL and pass the old one's signals to it. A 302 says the move is temporary, so search engines tend to keep the old URL indexed. Use 301 for permanent moves and 302 only when the old URL will come back.

### Does a 301 redirect lose SEO value?

Google has said that permanent redirects pass ranking signals to the new URL. What does cost you is redirecting to an unrelated page, long redirect chains, or removing redirects too early while old links still point at them.

### How do I create a 301 redirect in.htaccess?

Add a line such as Redirect 301 /old-page /new-page to the.htaccess file in your site's root. For patterns, enable RewriteEngine and use a RewriteRule with the R=301 and L flags. A 301 redirect generator writes these lines for you from a list of URL pairs.

### Is a 308 redirect better than a 301?

For ordinary pages, search engines treat them the same: both are permanent. 308 also guarantees the request method is kept, which matters for forms and APIs. Next.js and Vercel use 308 for permanent redirects by default.

### How long should I keep 301 redirects in place?

At least a year, which is Google's guidance for site moves. If the old URLs have backlinks or appear in emails, docs or bookmarks, keep the redirects indefinitely; they cost almost nothing to maintain.

### How many redirects in a chain are too many?

Aim for one hop. Googlebot follows up to 10 hops, but every extra hop slows visitors and adds a chance of failure. Point each old URL directly at its final destination.

## Related

- [Bulk Domain Authority Checker: How to Compare Many Domains at Once (Free)](https://abacklaunch.com/blog/bulk-domain-authority-checker-guide)
- [Canonical Checker Guide: What a Canonical Tag Does and How to Check Yours](https://abacklaunch.com/blog/canonical-tag-guide)
- [How to Compare Websites for SEO: A Side by Side Competitor Analysis (With a Worksheet)](https://abacklaunch.com/blog/compare-websites-seo-guide)
- [All founder guides](https://abacklaunch.com/blog)
