/ โ† Redirect Fixes / Set Up a 301 Redirect
In this guide
  1. What a 301 redirect is and how it works
  2. What a 301 redirect does for SEO
  3. How to set up a 301 redirect in .htaccess
  4. How to set up 301 redirects in nginx
  5. WordPress, Cloudflare and other platforms
  6. A worked example
  7. The fix, step by step
  8. Edge cases worth knowing
  9. Keeping your redirects clean
  10. Questions and answers

What a 301 redirect is and how it works

A 301 redirect is a server response that says a page has moved for good, and gives the new address. Its full name is 301 Moved Permanently. When a browser asks for the old URL, the server does not send the page. It sends a short response with the status code 301 and a Location header, and the browser immediately requests the new address instead:

$ curl -sI https://www.example.com/old-cakes/
HTTP/2 301
location: https://www.example.com/cakes/

The visitor barely notices; the new page simply loads. Browsers remember permanent redirects, so the next visit may go straight to the new address without asking the old one at all.

People sometimes call this a 301 error, but it is not an error. Status codes in the 300 range are redirects, and the 301 is the normal, correct way to move a page. It only becomes a problem when it points somewhere wrong, loops back on itself, or is one link in a long chain.

CodeNameMeaningUse it for
301Moved PermanentlyThe page has a new permanent addressMoved pages, changed URLs, merged content, domain moves
308Permanent RedirectSame as 301, but the browser must keep the request method, such as POSTAPIs and forms; Next.js uses it for permanent redirects
302FoundTemporary move; the old URL is still the real oneShort promotions, A/B tests, maintenance
307Temporary RedirectTemporary, keeping the request methodTemporary moves of forms or APIs

The choice between permanent and temporary is the choice that matters for search. The redirect checker guide explains how to read the full chain of responses for any URL.

What a 301 redirect does for SEO

For search engines, a 301 is a strong signal that the new URL should replace the old one. Google follows the redirect, crawls the new page, and over time shows the new URL in results in place of the old one. Links pointing at the old address keep their value, because Google treats the new page as the destination of those links. Google has said that 301, 302 and other server-side redirects do not lose PageRank, but a permanent redirect is the clearer signal for which URL should be shown.

A few things decide whether a 301 helps or quietly hurts:

๐Ÿ’ก After a redirect, Search Console lists the old URL under Page with redirect in the Pages report. That is expected and not a fault; it means Google saw the redirect and is indexing the destination instead.

How to set up a 301 redirect in .htaccess

On Apache and LiteSpeed hosting, which covers most shared hosting and many WordPress sites, redirects go in the .htaccess file in the site's root folder. Make a copy of the file before editing, because a typing mistake can take the whole site down with a 500 error.

A single page

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

The first path is the old address relative to the site root; the second is the full new address. This uses mod_alias, which is available on almost all Apache servers.

A whole folder with a pattern

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

A whole domain, with mod_rewrite

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?old-example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]

Place your redirect rules above the # BEGIN WordPress block, so WordPress does not handle the request first. Where you can, use one style throughout, either Redirect lines or RewriteRule lines, because mixing the two makes the order they run in harder to predict. The Apache redirects guide covers this in more detail.

How to set up 301 redirects in nginx

nginx does not read .htaccess. Redirects go in the server block for the site, usually in /etc/nginx/sites-available/, and you reload nginx after each change.

A single page

location = /old-cakes/ {
    return 301 https://www.example.com/cakes/;
}

A folder with a pattern

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

Bulk redirects with a map file

For dozens or hundreds of redirects, a map keeps them in one tidy file and is fast even with thousands of lines. The map block goes in the http context, for example in a file in /etc/nginx/conf.d/:

# /etc/nginx/conf.d/redirects-map.conf
map $uri $redirect_to {
    default "";
    include /etc/nginx/redirects.map;
}

# /etc/nginx/redirects.map  (old path, then new URL, each line ends with ;)
/old-cakes/         https://www.example.com/cakes/;
/about-us.html      https://www.example.com/about/;
/shop/gift-card     https://www.example.com/gift-cards/;

Then add one check inside the site's server block:

if ($redirect_to) {
    return 301 $redirect_to;
}

Test and reload with sudo nginx -t && sudo systemctl reload nginx. Using $uri matches the path without the query string; use $request_uri if you need to match exact URLs including parameters.

WordPress, Cloudflare and other platforms

// next.config.js
module.exports = {
  async redirects() {
    return [
      { source: '/old-cakes', destination: '/cakes', permanent: true },
    ];
  },
};

A worked example

Example Bakery renames its shop section from /products/ to /shop/ and merges two old pages, /wedding-cakes.html and /celebration-cakes.html, into one page at /cakes/occasions/. The site runs WordPress on Apache.

First, the owner exports every old URL from the sitemap and the top landing pages from analytics, and maps each one to its new home in a spreadsheet. Then she adds these lines above the WordPress block in .htaccess:

RedirectMatch 301 ^/products/(.*)$ https://www.example.com/shop/$1
Redirect 301 /wedding-cakes.html https://www.example.com/cakes/occasions/
Redirect 301 /celebration-cakes.html https://www.example.com/cakes/occasions/

She tests each old URL:

for u in /products/chocolate-cake/ /wedding-cakes.html /celebration-cakes.html; do
  curl -s -o /dev/null -w "%{http_code} -> %{redirect_url}\n" "https://www.example.com$u"
done

Every line prints 301 and the right destination. She then updates the menu and internal links to point at the new URLs directly, regenerates the sitemap, and checks one old URL with URL Inspection in Search Console. Within a few weeks the old URLs appear under Page with redirect and the new ones are indexed.

The fix, step by step

Step 1

List the old and new URLs

Make a two-column list of every old URL and the exact new URL it should go to. Pull old URLs from your sitemap, analytics landing pages and Search Console's Pages report, so nothing with traffic or links is missed. Match each old page to its closest equivalent rather than the home page. Check every new URL loads with a 200 status before you start, so you never redirect visitors to a page that does not exist.

Step 2

Choose where the redirects will live

Pick one place for your redirects: .htaccess on Apache or LiteSpeed hosting, the server block on nginx, Cloudflare Redirect Rules, or a WordPress redirect plugin if you cannot edit server files. Keeping them all in one place makes them easy to find and avoids two systems fighting over the same URL. If you are unsure which web server you have, run curl -sI against your site and read the server header.

Step 3

Back up the current configuration

Before editing, download a copy of .htaccess or copy the nginx site file with sudo cp to a dated backup name. If you use Cloudflare or a plugin, export the existing rules. A single mistyped character in a server file can stop the whole site loading, and a backup lets you put it right in seconds. Confirm the backup file exists and opens before you make any change.

Step 4

Add a single 301 redirect

Start with one redirect to prove the method works. On Apache, add Redirect 301 /old-page/ https://www.example.com/new-page/ above the WordPress block. On nginx, add a location = block with return 301 and the new URL, then run sudo nginx -t and reload. In Cloudflare or a plugin, create the rule with status 301. Test it with curl -sI and look for 301 and the right location.

Step 5

Add patterns and bulk redirects

Once one redirect works, add the rest. Use RedirectMatch or rewrite for whole folders that keep the same page names, and a map file on nginx, Cloudflare Bulk Redirects or a plugin CSV import for long lists of individual pages. Keep the rules ordered from most specific to most general so a broad pattern does not catch a page that has its own redirect. Save, test the syntax and reload.

Step 6

Test every old URL

Loop through your list with curl, printing the status code and redirect_url for each old address. Every one should return 301 and point straight at the final URL, which itself returns 200. Look out for 302s, two or more hops, loops and destinations that return 404. Test in a private browser window too, because your normal browser may have cached earlier attempts. Fix any problems before moving on.

Step 7

Update links, sitemap and canonicals

Change your menus, internal links and buttons to point at the new URLs directly, so visitors and crawlers do not pass through the redirect every time. Regenerate the XML sitemap so it lists only the new URLs, and make sure each new page's canonical tag points at itself. Ask sites that link to important old pages to update their links where that is easy. Then crawl the site and check no internal links still use old addresses.

Step 8

Check in Search Console and keep them

Use URL Inspection on a few old URLs and confirm Google sees the redirect, then inspect the new URLs and request indexing for the most important ones. Over the following weeks, the old URLs should move to Page with redirect in the Pages report as the new ones are indexed. Leave the redirects in place for at least a year, and longer for pages that still receive links or visits.

Edge cases worth knowing

Keeping your redirects clean

Questions and answers

1. What is a 301 redirect?

A 301 redirect is a server response that tells browsers and search engines a page has moved permanently to a new address. The server answers the old URL with the status code 301 Moved Permanently and a Location header naming the new URL, and the browser loads that address instead. Search engines follow it too, and over time replace the old URL with the new one in their results, carrying across most of the value of links that pointed at the old page.

2. How do I set up a 301 redirect?

You set up a 301 redirect by adding a rule where your site handles requests: the .htaccess file on Apache, the server block on nginx, a redirect rule in Cloudflare, or a redirect plugin in WordPress. On Apache, one line such as Redirect 301 followed by the old path and the full new URL is enough. On nginx, use a location block with return 301 and the new address. After adding it, test the old URL with curl or a redirect checker.

3. Is a 301 redirect an error?

No, a 301 is not an error, even though people often call it a 301 error. Status codes in the 300 range mean redirection, and 301 is the standard, correct way to tell browsers and search engines that a page has moved permanently. Errors are codes in the 400 range, such as 404 Not Found, and the 500 range, such as 500 Internal Server Error. A 301 only causes problems when it points to the wrong place, loops or forms a chain.

4. Do 301 redirects hurt SEO?

No, a well-placed 301 redirect does not hurt SEO; it is the recommended way to move a page without losing its search value. Google has said server-side redirects do not lose PageRank, and a 301 is a strong signal that the new URL should be shown. Problems come from redirecting to unrelated pages such as the home page, from long chains of redirects, from removing redirects too soon, and from leaving internal links and sitemaps pointing at the old URLs.

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

A 301 means the page has moved permanently, while a 302 means the move is temporary and the original URL should be kept. Search engines treat a 301 as a strong signal to index the new URL and drop the old one, and treat a 302 as a weaker signal, often keeping the old URL in results. Use a 301 for renamed pages, merged content and domain moves, and a 302 only for genuinely short-term changes such as a seasonal promotion.

6. How long should I keep a 301 redirect?

Keep a 301 redirect for at least a year, and for as long as the old URL still gets visits or has links pointing to it. Google recommends keeping redirects in place for at least a year so it has time to process the move and transfer signals. Removing a redirect turns the old URL into a 404, so visitors following old links or bookmarks land on an error. Redirects cost very little to keep, so many sites never remove them.

7. How do I check that a 301 redirect is working?

Check it by requesting the old URL and looking at the status code and Location header in the response. Run curl -sI followed by the old URL in a terminal, or use a redirect checker, and you should see 301 and the correct new address in a single hop. Test in a private browser window as well, because browsers cache redirects. In Search Console, URL Inspection on the old address should report that the page redirects to the new one.

Check your redirects for chains and loops

Our redirect checker follows every hop from an old URL to its final page and shows each status code, so you can confirm every 301 lands in one step on a working page.

Open Redirect Fixes โ†’
๐Ÿ’ฌ Got a problem?
Related Guides: All Redirect Fixes  ·  301 redirect not working  ·  Fixing redirect chains  ·  Redirects in Apache  ·  Redirect a domain with 301s  ·  Learning Hub

About aiwebpageseo

aiwebpageseo.com is a data-driven SEO and AEO (Answer Engine Optimisation) platform providing a free suite of technical SEO tools. Rather than relying on AI-theorised assumptions, the platform analyses live URL performance, delivering objective diagnostics, page speed metrics, CLS debugging, and site crawl data alongside actionable technical tutorials.