Websites & Hosting

How to Redirect Pages Without Losing Visitors

Plan and set up redirects when pages move, choose the right status code, avoid chains and loops, and test that old links still lead somewhere useful.

Key takeaways

  • Redirect each old address to its closest equivalent instead of sending everything to the home page.
  • Use 301 or 308 for permanent moves and 302 or 307 for temporary ones.
  • Server, host or CDN redirects are more reliable than redirects done with page scripts.
  • Point old URLs straight at the final destination to avoid chains and loops.
  • Build the redirect map before a redesign or migration, then watch logs for addresses you missed.

When a page's address changes, set up a server-side redirect from the old URL to the closest matching new one, use a permanent status code if the move is permanent, and test every important old address. Visitors following bookmarks, shared links and search results then arrive where they meant to go.

Skip that step and they hit "not found" pages. Links other sites gave you stop helping, and search engines have to guess where your content went.

What a redirect does

A redirect is a response that says "what you asked for is somewhere else." The server returns a 3xx status code with a Location header holding the new address, and the browser requests that instead. It happens in a fraction of a second, and most people notice only that the address bar changed.

A permanent redirect in action
Browser Web server GET /old-menu 1 301 with Location: /menu 2 Browser may remember this GET /menu 3 200 OK and the page 4 Browser Web server GET /old-menu 1 301 with Location: /menu 2 Browser may remember this GET /menu 3 200 OK and the page 4

Pick the right status code

Code Meaning Request method Typical use
301 Moved permanently May change POST to GET Renamed pages, new domain
302 Found, temporary May change POST to GET Short-term detour
307 Temporary redirect Preserved Temporary move of a form or API
308 Permanent redirect Preserved Permanent move of a form or API

For ordinary pages, 301 for permanent and 302 for temporary cover most needs. The finer points are in comparing 301, 302, 307 and 308.

Browsers can cache permanent redirects for a long time. If you aren't sure yet, test with a temporary code and switch once you've confirmed the mapping. A wrong 301 can linger in visitors' browsers after you fix the server.

When content is gone with no replacement, don't force a redirect. Return 404, or 410 to say it was removed deliberately, on a helpful error page with search and links to popular sections.

Redirect, canonical or leave it alone

Redirects aren't the answer to every address question. A canonical link element tells search engines which of several similar pages you consider the main one, while leaving all of them reachable. Use it for variations visitors still need, such as a product list sorted different ways or a page opened with tracking parameters.

Situation Use
Page renamed or moved Permanent redirect
Seasonal page temporarily replaced Temporary redirect
Same content reachable at several useful addresses Canonical link element
Content removed with nothing equivalent 404 or 410
Site briefly down for work 503 with Retry-After

You can often avoid the problem altogether. Choose addresses that describe the content without details likely to change, such as the year, the current category name or the technology behind the site. Changing a headline doesn't require changing the address. Every URL you leave alone is a redirect you never have to maintain.

Before approving a redesign that renames everything, ask what the new addresses gain. Sometimes the answer is a clearer structure worth the work. Often the old paths can simply stay.

Build a redirect map

Before changing many addresses, make a two-column list: old URL and new URL. Gather old addresses from several sources, since none is complete:

  • Your content system's export and XML sitemap.
  • Server logs and analytics, which show what people actually request.
  • Your search engine's webmaster tools, including pages other sites link to.
  • Printed materials, QR codes, email templates and ads that contain addresses.

Match each old page to the most similar new one. A discontinued product might point to its replacement or its category. If you merged three articles into one, all three point to the merged article.

Sending everything to the home page frustrates people, who have to start searching again, and search engines may treat such redirects much like missing pages.

Set up the redirect

Use whatever sits closest to the visitor and that you can maintain: a CDN rule, your host's redirect panel, the web server configuration or a content system plugin.

On Apache, in a virtual host or .htaccess file where allowed:

Redirect 301 /old-menu https://www.example.com/menu

Redirect matches path prefixes, so requests below /old-menu/ are carried over too, with the remainder appended. Use RedirectMatch or rewrite rules when you need exact or pattern matching.

On nginx, inside the server block:

location = /old-menu {
    return 301 /menu;
}

location /blog/ {
    rewrite ^/blog/(.*)$ /news/$1 permanent;
}

The first handles one exact path. The second moves a whole section while keeping the rest of each address. Test the configuration with sudo nginx -t before reloading.

Platforms without server access usually accept a redirect list or file in their own format. Check their documentation for limits and rule order.

Redirects in the page itself

A meta refresh tag or a script can move visitors when you have no server control. These are slower, can confuse the back button and assistive technology, and give a weaker signal to machines. Use them only when nothing better is available, and include a visible link.

Moving a whole domain or switching to HTTPS

When changing domains, redirect each old URL to the same path on the new domain where possible. An nginx catch-all for the old name looks like this:

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

The old domain needs its listen directives, and a valid certificate if visitors arrive over HTTPS; the redirect can't happen until the secure connection succeeds. Keep the old domain registered and redirecting for as long as links to it matter, which is often years. A lapsed domain can be picked up by someone else, who then receives your old visitors.

For HTTP to HTTPS and for the www choice, aim for a single hop from any variant to the final form. After HTTPS works reliably, consider HSTS, which tells browsers to use it automatically.

Avoid chains, loops and traps

Healthy and unhealthy redirect patterns
Direct Old URL goes straight to final URL One extra request Easy to maintain Chain A to B to C to D Each hop adds delay Clients may give up if it is long Loop A to B and B back to A Browser shows an error Often caused by two layers disagreeing Direct Old URL goes straight to final URL One extra request Easy to maintain Chain A to B to C to D Each hop adds delay Clients may give up if it is long Loop A to B and B back to A Browser shows an error Often caused by two layers disagreeing

Chains accumulate over successive redesigns. When you add a new move, update older rules so they point at the newest destination.

Loops commonly happen when a CDN connects to your server over plain HTTP while the server redirects all HTTP to HTTPS. The fix is to make both layers agree, usually by having the CDN connect with HTTPS. Content systems can also fight server rules about the www prefix or trailing slashes.

Other traps include losing query strings that campaigns rely on, case sensitivity in paths and broad patterns that catch pages you didn't mean to move. Never build a redirect that sends visitors to whatever address a query parameter names without checking it, since abusers exploit such open redirects to lend your domain to phishing links.

Keep the rules manageable

A few redirects are easy to read. Several hundred scattered across plugins, server files and CDN settings are not, and rules in one layer can silently override another. Pick one primary place for them and note any exceptions.

Order matters in most systems: the first matching rule often wins. Put specific rules above broad patterns. A section-wide rewrite placed first can swallow the one page that was meant to go somewhere else.

For large sets on nginx, a map block holds old and new paths as a lookup table, which is tidier than hundreds of location blocks:

map $uri $new_uri {
    default        "";
    /old-menu      /menu;
    /staff         /about/team;
}

server {
    if ($new_uri != "") {
        return 301 $new_uri;
    }
}

The map block belongs in the http context, and the server block shown holds only the relevant lines. This version drops query strings, so add them back if your campaigns or search pages depend on them.

Redirects also pass through campaign tags only if the rule preserves them. If you rely on those parameters, include one tagged address in your tests and confirm the values arrive in your reports.

Test before and after

Inspect a redirect without browser caching getting in the way:

curl -I https://www.example.com/old-menu
curl -sIL -o /dev/null -w "%{http_code} %{num_redirects} %{url_effective}\n" https://www.example.com/old-menu

The first shows the status and Location header. The second follows the redirects and prints the final status, the number of hops and where you ended up. Run it over your whole map with a small script, and spot-check by hand that destinations make sense. A 200 on the wrong page is still a failure.

After launch:

  1. Update internal links, menus, canonical tags and sitemaps to use new addresses directly.
  2. Ask important partners to update their links.
  3. Watch for 404s in your server logs and add the missing rules.
  4. Check your webmaster tools for crawl errors over the following weeks.

If you are moving hosts or domains at the same time, change as little else as you can in one step. The sequence in migrating to a new host helps keep causes separate when something looks wrong.

How long to keep redirects

Keep them as long as people or machines still request the old address. A simple rule costs almost nothing to run. Review the list yearly, collapse chains and remove entries only when logs show no meaningful use. Store the map in version control with a short note on why each batch exists, so the next person doesn't delete it as clutter.

Written for 4Internet with AI writing tools and not reviewed line by line by a person. Check anything you rely on with the maker, provider or standard concerned. Report an error.

Keep reading

All 45 articles in Websites & Hosting →

Latest news on this topic