Search Converts LLC BBB Business Review
1-800-481-8638The Commit
Search Converts LLC BBB Business Review
Home / Blog / How to set up 301 redirects
Blog · 10 min read

How to set up 301 redirects, then prove they work

Server-by-server code, chain fixes and the one-line test we run on every redirect.

By the DenverSEO.io team · 2026-11-17

To set up a 301 redirect, add a rule at the server or hosting layer that answers requests for the old URL with status 301 and a Location header pointing to the new URL. On Apache that is a Redirect 301 line in .htaccess; on Nginx, a return 301; on Netlify, a line in _redirects. Point every old URL straight at its final destination in one hop, then test each one with curl -I before you call it done.

Redirects are small pieces of code with large consequences. A clean one hands a page's history, links and rankings to its new address. A sloppy one strands them: a 302 that was meant to be temporary for a week and stayed for three years, a chain of four hops left behind by three redesigns, a hundred retired service pages all dumped on the home page. None of these throw an error. The site looks fine in a browser. The damage only shows up later, in Search Console and in the phone log.

This guide gives you the exact rule syntax for the platforms we work on most, a way to find and flatten redirect chains, and the test we run on every redirect before a launch. If you are planning a full site move, start with our migration checklist and come back here for the code.

Which redirect status code should you use?

Google sorts redirects into two groups. Permanent redirects tell it to show the new target in search results. Temporary redirects tell it to keep showing the source. Here is the full set:

TypeMeaningUse it when
301 Moved PermanentlyPermanentThe default for a page that has moved for good.
308 Permanent RedirectPermanentSame as 301 for search, but the HTTP spec requires clients to keep the request method, so a form POST stays a POST. Useful for APIs and form endpoints.
302 Found / 307 Temporary RedirectTemporaryA short-lived detour, such as a seasonal promotion or a page under maintenance. 307 keeps the method.
303 See OtherTemporaryAfter a form submission, to send the browser to a results or thank-you page with a GET.
Meta refresh, 0 secondsTreated as permanent by GoogleStatic hosts where you cannot set server rules.
Meta refresh with a delayTreated as temporary by GoogleAlmost never, for SEO purposes.
JavaScript location redirectOnly seen if rendering succeedsLast resort. Google says it may never see a JavaScript redirect if rendering fails.

Google's own recommendation is a permanent server-side redirect whenever possible. Our rule of thumb: if you are not sure whether a move is temporary, it is not. Use a 301.

How do you set up a 301 redirect in Apache (.htaccess)?

For a handful of single-page moves, mod_alias is the simplest tool. One line per redirect, old path first:

# .htaccess in the site root
Redirect 301 /furnace-repair.html https://www.example.com/furnace-repair/
Redirect 301 /about-us/ https://www.example.com/about/

For patterns, RedirectMatch takes a regular expression. This moves an entire old blog folder to a new one, keeping the slug:

RedirectMatch 301 ^/news/(.*)$ https://www.example.com/blog/$1

For protocol and hostname rules, use mod_rewrite, and send both fixes in a single hop. This is the version we use: anything on http:// or on the bare domain goes straight to https://www., with no intermediate stop:

RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.example.com%{REQUEST_URI} [L,R=301]

A common mistake is writing those as two separate rules, one for HTTPS and one for www. That turns http://example.com/page into a two-hop chain on every request. Also avoid mixing Redirect and RewriteRule for the same URLs; the two modules run at different stages and the results can surprise you.

How do you set up a 301 redirect in Nginx?

Nginx uses return, which is faster and clearer than rewrite for straight redirects. The host and protocol rule gets its own server block:

server {
    listen 80;
    listen 443 ssl;
    server_name example.com;
    # (ssl_certificate lines go here)
    return 301 https://www.example.com$request_uri;
}

server {
    listen 80;
    server_name www.example.com;
    return 301 https://www.example.com$request_uri;
}

A single page move is an exact-match location:

location = /furnace-repair.html {
    return 301 /furnace-repair/;
}

For more than a few dozen redirects, use a map. It keeps the list in one readable table and is efficient even with thousands of entries. The map block lives in the http context, outside any server:

map $uri $new_uri {
    default                     "";
    /furnace-repair.html        /furnace-repair/;
    /ac-repair.html             /air-conditioning-repair/;
    /services/water-heaters/    /water-heater-installation/;
}

server {
    server_name www.example.com;
    # ...
    if ($new_uri) {
        return 301 $new_uri;
    }
}

An if that only calls return is one of the safe uses of if in Nginx. Run nginx -t before every reload.

How do you set up redirects on Netlify, Vercel and Cloudflare?

On Netlify, add a plain text file named _redirects to the publish folder. Status 301 is the default, but write it anyway so the next developer does not have to remember that:

/furnace-repair.html   /furnace-repair/            301
/news/*                /blog/:splat                301

On Vercel, redirects go in vercel.json. Setting permanent: true sends a 308, which Google treats the same as a 301:

{
  "redirects": [
    { "source": "/furnace-repair.html", "destination": "/furnace-repair/", "permanent": true },
    { "source": "/news/:slug", "destination": "/blog/:slug", "permanent": true }
  ]
}

On Cloudflare, use Single Redirects for pattern rules and Bulk Redirects for long lists of one-to-one moves. Both answer at Cloudflare's edge before the request reaches your server, which is useful when the origin is a host you cannot configure. Choose 301 as the status code in the rule; check it, because the form does not always default to it.

What about GitHub Pages and other static hosts?

Some static hosts, including GitHub Pages, have no server-side redirect rules. Two workable options:

  • Jekyll sites can use the jekyll-redirect-from plugin, which GitHub Pages supports. It generates the redirect pages for you from front matter.
  • Any static site can leave a small HTML file at the old path with an instant meta refresh. Google treats a zero-second meta refresh as permanent. Add a canonical to the new URL and a plain link for people and tools that do not follow the refresh:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Page moved</title>
<link rel="canonical" href="https://www.example.com/furnace-repair/">
<meta http-equiv="refresh" content="0; url=https://www.example.com/furnace-repair/">
</head>
<body>
<p>This page moved to <a href="https://www.example.com/furnace-repair/">/furnace-repair/</a>.</p>
</body>
</html>

Save it as furnace-repair.html or as old-folder/index.html, whichever matches the old URL exactly. If you have the choice of a host or a CDN that supports real 301s, take it, but this pattern works and we use it where the platform leaves no other option.

How do you find redirect chains?

A redirect chain is any request that takes more than one hop to reach a 200 page. Chains slow every visitor down, add a round trip on mobile connections, and give crawlers more chances to give up. They build up quietly, one redesign at a time.

Check one URL with curl. The -L flag follows redirects and -w prints a summary at the end:

curl -s -o /dev/null -L \
  -w '%{num_redirects} hops, final %{http_code}: %{url_effective}\n' \
  http://example.com/furnace-repair.html

To see every hop, ask for headers only and follow along:

curl -sIL http://example.com/furnace-repair.html | grep -iE '^(HTTP|location)'

For a whole list of legacy URLs, a short Python script does the job. Put one old URL per line in old-urls.txt:

import requests

TEMP = {302, 303, 307}

for url in open("old-urls.txt").read().split():
    r = requests.get(url, allow_redirects=True, timeout=15)
    hops = [h.status_code for h in r.history]
    if r.status_code != 200:
        flag = "BROKEN"
    elif len(hops) > 1:
        flag = "CHAIN"
    elif any(code in TEMP for code in hops):
        flag = "TEMP"
    else:
        flag = "ok"
    print(f"{flag:7} {url} {hops} -> {r.status_code} {r.url}")

Anything flagged CHAIN, TEMP or BROKEN needs attention. Your server logs tell you which of those old URLs crawlers still request, so you can fix the busiest first; our log file analysis walkthrough shows how to pull that list.

A worked example: flattening three redesigns into one hop

Here is a composite of a pattern we untangle regularly, with the details changed. A Denver heating and cooling company has had three websites. The 2016 site used .html pages on the bare domain over HTTP. The 2020 rebuild moved services under /services/ and added HTTPS. The 2026 rebuild flattened the URLs again and settled on www. Each developer added redirects from the site before theirs, and nobody went back further.

Running the curl hop check on a link from an old directory listing shows the result:

$ curl -sIL http://example.com/furnace-repair.html | grep -iE '^(HTTP|location)'
HTTP/1.1 301 Moved Permanently
Location: https://example.com/furnace-repair.html
HTTP/2 301
location: https://www.example.com/furnace-repair.html
HTTP/2 302
location: https://www.example.com/services/furnace-repair/
HTTP/2 301
location: https://www.example.com/furnace-repair/
HTTP/2 200

Four hops, and one of them is a 302 left over from the 2020 launch weekend. The page still loads in a browser, so nobody noticed. The fix:

  1. Collect every historical URL. Old sitemaps, an export of top pages from Search Console, backlink reports and the server log all go into one list.
  2. Map each one to its final destination. Not to the next site's URL, to today's URL. /furnace-repair.html and /services/furnace-repair/ both point straight to /furnace-repair/.
  3. Combine the host and protocol rule into one hop, using the Apache or Nginx pattern above.
  4. Replace the 302 with a 301 and delete the old per-site rule files so they cannot stack again.
  5. Update internal links, canonicals and the XML sitemap to use final URLs only. A redirect is for the outside world; your own site should never link through one.
  6. Rerun the script and keep the output with the project notes, so the next redesign starts from a known map.

After the change, the same request lands in one hop:

$ curl -sIL http://example.com/furnace-repair.html | grep -iE '^(HTTP|location)'
HTTP/1.1 301 Moved Permanently
Location: https://www.example.com/furnace-repair/
HTTP/2 200

Our website migration SEO page includes a redirect map builder that does the first matching pass for you, which helps on step two when the list runs to hundreds of URLs.

What are the most common redirect mistakes?

  • Sending retired pages to the home page. If there is no close replacement, a 404 or 410 is more honest. Mass redirects to an irrelevant page can be treated as soft 404s, which helps no one.
  • Trailing slash and case mismatches. /Furnace-Repair, /furnace-repair and /furnace-repair/ are three different URLs to a server. Pick one form and redirect the others to it in a single hop.
  • Dropping query strings that matter. Apache's Redirect passes the query string through by default; some platform rules do not. Test with a tracking parameter attached.
  • Redirect loops. Two rules that point at each other, often a CMS rule fighting a server rule. Browsers show an error; crawlers simply give up.
  • Redirecting to a page that is noindexed or blocked. The redirect passes the visitor to a page Google is told to ignore. Check the destination's directives too; our guide to noindex vs robots.txt explains what to look for.
  • Removing redirects too early. Old links on other websites keep sending people for years.

How long should you keep 301 redirects?

Google's site move documentation recommends keeping redirects for as long as possible, and generally for at least a year. In practice, we keep them indefinitely. A redirect rule costs almost nothing to serve, and the inbound links pointing at old URLs from directories, news articles and partner sites rarely get updated. Removing redirects to tidy a config file is one of the few cleanup jobs that can lose real traffic.

Where redirects fit in a rebuild

Redirect planning should start before design does. The URL structure of the new site decides which pages need a rule, and the content inventory decides where each one should land. If you are weighing a new site and want redirects handled as part of the build rather than as an afterthought, Eye To Ad Media's custom website builds include the full redirect map, and our redesign SEO page covers the rest of what has to carry over. Either way, the test is the same: every old URL, one hop, a 301, and a 200 at the end.

Sources

FAQ

Quick answers

How do I set up a 301 redirect?

Add a rule at your server or host that answers the old URL with status 301 and a Location header for the new URL: a Redirect 301 line in Apache's .htaccess, a return 301 in Nginx, a line in Netlify's _redirects file, or a redirect in vercel.json. Then test it with curl -I.

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

A 301 is permanent and tells Google to show the new URL in search results. A 302 is temporary and tells Google to keep showing the old URL. Use 301 for any move you do not plan to undo.

Is a 308 redirect the same as a 301 for SEO?

Google treats both as permanent redirects. The difference is technical: a 308 requires the browser to keep the request method, so a form POST stays a POST. Vercel sends 308 when a redirect is marked permanent.

How do I find redirect chains on my site?

Run curl -sIL on an old URL to see every hop, or use a short script that follows each URL in a list and flags any that take more than one redirect. Then point every old URL straight at its final destination.

Can I do a 301 redirect on GitHub Pages?

GitHub Pages has no server redirect rules. Jekyll sites can use the jekyll-redirect-from plugin, and any static site can place an HTML file at the old path with an instant meta refresh and a canonical tag. Google treats a zero-second meta refresh as a permanent redirect.

How long should I keep 301 redirects in place?

Google's site move guidance says to keep redirects as long as possible, generally at least a year. We keep them indefinitely, because old links on other sites keep sending visitors for years and a redirect costs almost nothing to serve.

60-second project scope

Tell us what you are working on. Get a straight answer.

Four taps and your contact info. An engineer (not a salesperson) reviews it and tells you what we would do, what it costs and whether you even need us.

What are you working on?

What is it built on?

What keeps you up at night?

When does it need to happen?

Where should we send your answer?

Search Converts LLC BBB Business ReviewBBB Accredited Business. A real person reads every request.

Got it. Here is what happens next.

  1. An engineer reviews your answers today.
  2. You get a call or email with what we would fix first, and why.
  3. If you do not need us, we will tell you that too.
Can't wait? Call 1-800-481-8638

Want an engineer to look at yours?

Fifteen minutes on the phone usually tells us whether we can help, and how much.

☎ Call now