FREE TOOL · NO SIGNUP TO PREVIEW

Generate 301 Redirect Rules in Seconds

Migrating a site or fixing broken URLs? Add your old → new pairs and get ready-to-paste Apache, Nginx, and Next.js redirect rules — copy or download in one click.

Redirect inputs

1 row
Rule 1
Example output — enter your own old → new pairs above to generate your redirects.
301 redirect3 rules

Apache (.htaccess) config

# Redirect rules generated by SemlyPro — paste into your site root .htaccess
<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteRule ^old-blog/seo-tips$ /blog/seo-tips [R=301,L]
  RewriteRule ^services/old-page$ /services/new-page [R=301,L]
  RewriteRule ^2023/announcement$ https://example.com/news/announcement [R=301,L]
</IfModule>

Paste into the .htaccess file in your site root. Requires mod_rewrite (enabled on most hosts).

Resolved redirect map

FromToType
/old-blog/seo-tips/blog/seo-tips301
/services/old-page/services/new-page301
/2023/announcementhttps://example.com/news/announcement301
The Complete Guide

How to Write 301 Redirect Rules That Keep Your Rankings

5 MIN READ

Understand with AI

Discuss with your preferred AI assistant

301
Permanent moves

The status code that passes ranking signals to the new URL — use it for migrations and URL changes.

~100%
Equity preserved

A correctly implemented 301 transfers the vast majority of link equity to the destination over time.

1 yr+
Keep redirects live

Google needs repeated crawls of the old URL before it fully consolidates signals to the new one.

When you move a page, rename a URL, or migrate a whole site, the old address doesn't disappear — it lives on in Google's index, in backlinks, and in your visitors' bookmarks. A redirect is the instruction that quietly forwards every one of those requests to the right new location. Get redirects right and a migration is invisible to users and search engines alike. Get them wrong and you lose rankings, traffic, and revenue overnight.

This guide explains the redirect types that matter for SEO, how to write redirect rules for Apache, Nginx, and Next.js, and the common mistakes that quietly erode organic traffic — so you can hand off a clean, validated redirect map every time.

What Is a Redirect Rule?

A redirect rule tells a web server: "when a request comes in for URL A, respond with a status code that points the browser to URL B instead." The browser (and Googlebot) follows that instruction automatically. The two codes you'll use almost every day are 301 and 302.

A redirect rule has three parts: a source (the old path or URL to match), a destination (where to send the request), and a status code (which signals whether the move is permanent). The syntax for expressing those three parts differs by server, which is why the same logical redirect looks different in .htaccess, an Nginx config, and a Next.js file.

301 vs 302: Which Redirect Should You Use?

Choosing the wrong status code is the single most common — and most damaging — redirect mistake. Here's the rule of thumb:

StatusMeaningSEO behaviourUse when
301Moved PermanentlyPasses ranking signals (link equity) to the new URL; search engines update the index to the destination.The move is permanent — site migration, URL change, merged pages, HTTP → HTTPS.
302Found (Temporary)Keeps the original URL in the index; signals are not consolidated to the destination.The move is temporary — A/B tests, geo or device routing, a page down for maintenance.

If you're permanently moving a page and you want it to keep its rankings, use a 301. Reserve 302 for genuinely temporary situations. Using a 302 for a permanent move means Google keeps showing the old URL and may dilute the equity you worked hard to earn.

How to Write Redirect Rules for Each Server

Apache (.htaccess)

Apache uses the mod_rewrite module. Rules live in a .htaccess file in your site root, wrapped in an IfModule block. A redirect uses RewriteRule with an [R=301,L] flag, where R sets the status code and L stops processing further rules. Patterns are matched against the path without the leading slash.

Nginx

Nginx redirects go inside a server { } block. The cleanest form is an exact location = /old-path { return 301 /new-path; }. For pattern matching you switch to a regex location (location ~ "^/old/.*$"), and the ~* modifier makes the match case-insensitive. After editing, validate with nginx -t before reloading.

Next.js

Next.js handles redirects in code via the asynchronous redirects() function in next.config.js. Each entry has a source, a destination, and a permanent boolean — true emits a 301, false emits a 307 (the modern temporary equivalent of a 302 that preserves the HTTP method).

Redirect Best Practices for SEO

  • Redirect to the most relevant page, not blanket-to-homepage. A "soft 404" — redirecting many deleted pages to the homepage — is treated by Google as a 404 and passes no equity.
  • Avoid redirect chains. A → B → C wastes crawl budget and leaks signals. Always point the original source straight to the final destination.
  • Never create loops. A redirect whose source equals its destination, or that points back through the chain, will fail. Validate before you ship.
  • Map one source to one destination. Duplicate source rules are ambiguous; the server uses whichever it reads first.
  • Use absolute HTTPS destinations when moving between domains, and root-relative paths for same-site moves.
  • Keep redirects in place for at least a year — Google needs repeated crawls to fully transfer signals to the new URL.

Common Redirect Mistakes

  • Using a 302 for a permanent move, so rankings never transfer.
  • Redirecting every removed URL to the homepage instead of a relevant page.
  • Building long redirect chains during multiple migrations.
  • Forgetting to redirect both www and non-www, or HTTP and HTTPS.
  • Leaving the old URLs in the sitemap after redirecting them.

Expert Tips

Redirect to the closest match, not the homepage

Mapping deleted pages to the homepage is treated by Google as a soft 404 and passes no equity. Send each old URL to the most relevant live page instead.

Kill redirect chains

A → B → C wastes crawl budget and leaks ranking signals at every hop. Always point the original source straight to the final destination.

Frequently Asked Questions

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

A 301 is a permanent redirect: it passes ranking signals to the new URL and tells search engines to replace the old URL in their index. A 302 is temporary: the original URL stays indexed and link equity is not consolidated. Use 301 for permanent moves and 302 only when the change is genuinely temporary.

Do 301 redirects pass SEO value?

Yes. A 301 passes the vast majority of ranking signals — including link equity from backlinks — to the destination URL. Transfer is not instant; Google needs to recrawl the old URL several times before it fully consolidates the signals, which is why you should keep redirects live for at least a year.

Where do I put redirect rules?

On Apache, add them to the .htaccess file in your site root (or the main server config). On Nginx, place them inside the relevant server { } block and reload after running nginx -t . On Next.js, add them to the redirects() function in next.config.js .

How many redirects can I add without hurting performance?

A few hundred well-formed rules are fine. The real performance risk is redirect chains , not raw count — each hop adds a round trip. For very large redirect maps, prefer a flat one-to-one map and, on high-traffic sites, consider managing redirects at the CDN or edge for speed.

Related guides

Related tools