Skip to content

WordPress 301 redirect: with a plugin, on the server and without one

· The AYT team · 6 min read

Man typing on a laptop at a wooden table, with a phone and notebook beside it

A 301 redirect tells browsers and search engines that a page has moved permanently to a new address. Google replaces the old address with the new one in its results and passes on its ranking signals, and visitors following old links end up in the right place. In WordPress you can set one up in three ways: with a plugin such as Redirection, from your hosting panel (that is, in the web server) or, for a whole domain, in Cloudflare.

301, 302, 307 or 308

Code What it means When to use it
301 permanent move the page or domain won't return to the old address
302 temporary move a promotion, a page in progress, a test
307 temporary, keeps the request method (e.g. POST) apps and forms, rarely on ordinary sites
308 permanent, keeps the request method the same, for APIs and forms

For pages and posts, 301 and 302 are all you need. Careful: browsers remember a 301. If you got the target wrong, visitors who already saw it will keep being sent there until they clear their cache. Test every new redirect in a private window.

When you need a 301

WordPress automatically redirects posts whose slug (the part of the address after the domain) you changed. It doesn't do it in other cases, where you add the redirect yourself:

  • you deleted a page and its content now lives in another;
  • you merged two posts into one;
  • you changed the permalink structure (for example from /2024/05/post/ to /post/);
  • you renamed a category or a product page in a shop;
  • you moved the site to another domain.

Option 1: the Redirection plugin

Redirection, written by John Godley, is one of the most used free redirect plugins.

  1. Install it from Plugins → Add Plugin and activate it.
  2. Open Tools → Redirection and go through the setup wizard. Keep permalink change monitoring and the 404 log ticked.
  3. Add the redirect: in "Source URL" enter the old address without the domain, for example /old-page/, and in "Target URL" the new one, /new-page/. The default code is 301.
  4. Open the old address in a private window and check where you land.

For many addresses with the same pattern, use a regular expression. For example, to move everything under /blog/ to the root, tick "Regex" and use the source ^/blog/(.*)$ and the target /$1.

Redirection's 404 log is just as useful: it shows which addresses visitors and Google ask for that no longer exist, so you can redirect them to the right page. SEO plugins have redirect modules too: Rank Math in its free version, Yoast SEO in Premium.

The downside of plugins: the redirect happens only after WordPress has loaded, so every request for an old address starts PHP and queries the database. For a few dozen redirects that doesn't matter. For thousands, the server-side option is faster.

Option 2: without a plugin, on the server

On an Apache or LiteSpeed server, the redirect goes in .htaccess, above the WordPress rules:

Redirect 301 /old-page/ https://yourdomain.com/new-page/

nginx doesn't read .htaccess at all. The equivalent goes in the server configuration:

location = /old-page/ {
    return 301 https://yourdomain.com/new-page/;
}

On shared hosting you have no access to the nginx configuration, so you use the redirects page in your panel, which writes the rule for you. Which other .htaccess rules stop working on nginx, and what replaces them, is in the guide to .htaccess on nginx.

Option 3: a 301 redirect for a whole domain

When you move the site to another domain, every old address must lead to the same path on the new domain; if they all go to the home page, the inner pages' signals are lost. In nginx, the rule for the old domain looks like this:

return 301 https://new-domain.com$request_uri;

If the old domain goes through Cloudflare, you can do the same under Rules → Redirect Rules, without a server (details in the Cloudflare guide for WordPress). The rest of a domain move, including telling Google Search Console about the change, is in the guide to moving WordPress to a new domain without losing SEO.

Mistakes that break redirects

  • Redirect chains: A sends to B, B to C. Make A send straight to C, and update internal links to the final address.
  • Every 404 sent to the home page. Google treats them as "soft 404s", and visitors don't find what they were looking for. Redirect only to a page with equivalent content.
  • Loops: A sends to B, B back to A. The browser shows ERR_TOO_MANY_REDIRECTS; the fix is in the guide to the redirect loop.
  • A 302 set by mistake for a permanent move. Google keeps the old address in its index for longer.
  • Forgotten variants: http://, www and the trailing slash. Pick one form of the address and redirect the others to it.

The surest test is from the command line:

curl -I https://yourdomain.com/old-page/

The response must contain 301 and a location: line with the new address.

Frequently asked questions

How long should I keep a 301 redirect?

As long as you can. Google recommends at least a year for a site move, and links to the old addresses on other sites stay there for years. A redirect costs almost nothing, so there's no point removing it.

Will I lose Google rankings with a 301 redirect?

A 301 to a page with the same content passes on the old page's signals. Rankings may move about for a few days while Google reindexes, but the redirect itself is no penalty.

Redirects on AYT hosting

On AYT WordPress hosting you set up redirects in the panel, with no plugin: on the domain's Redirects page you write one per line, with the old address, the target and 301 (permanent) or 302 (temporary), for example /old-page https://yourdomain.com/new-page 301. Each rule matches one exact path; for patterns (regex), the Redirection plugin is still the tool. In the same panel you switch on "Force HTTPS Redirect" and pick the www or bare version under "Preferred address".

The Redirects page in the AYT panel

The rules go into nginx, so they apply before WordPress starts, and a wrong redirect is changed in the same place.

More articles

All articles