Skip to content

Search WPDesignVault

Try "image", "json", "schema" or "contrast". Use arrow keys to move through results.

WordPress Guides

How to Set Up 301 Redirects in WordPress Without a Plugin

When a URL changes, a 301 redirect sends visitors and search engines to the new address and tells them the move is permanent. Done well, people never notice and search engines carry…

On this page

When a URL changes, a 301 redirect sends visitors and search engines to the new address and tells them the move is permanent. Done well, people never notice and search engines carry the old page’s signals over. Done badly, you get broken links, redirect chains and lost traffic. Here is how to set up redirects in WordPress without a plugin, and how to check they work.

Which redirect code to use

CodeMeaningUse it when
301Moved permanentlyA page has a new URL for good: renamed slug, merged content, new domain.
302 / 307TemporaryShort-term changes: a seasonal page, maintenance, A/B tests.
308Permanent, keeps the methodAPIs and form endpoints where a POST must stay a POST.
410GoneContent removed with no replacement, and you want it dropped from search faster.

For ordinary page moves, use 301. Google treats 301 and 308 as permanent and passes signals through them.

Do you even need to add one?

WordPress already redirects some changes by itself. If you edit a published post’s slug, WordPress remembers the old slug and redirects it. It does not handle changes to pages’ parent structure reliably, category base changes, or moves between sites, so those need explicit rules.

Option 1: .htaccess (Apache and LiteSpeed)

Add rules above the # BEGIN WordPress block.

A single page

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

A pattern, such as a renamed folder

RewriteEngine On
RewriteRule ^blog/(.*)$ /articles/$1 [R=301,L]

Redirect matches the start of the path, so “Redirect 301 /shop” also catches /shop-sale/. Use the RewriteRule form with ^ and $ anchors when you need an exact match.

A whole domain move

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

This keeps the path, so old-domain.com/about/ goes to new-domain.com/about/. That one-to-one mapping matters: sending everything to the new home page loses most of the value.

Option 2: Nginx

Nginx does not read .htaccess. Ask your host to add rules to the server block, or add them yourself if you manage the server:

location = /old-page/ { return 301 https://example.com/new-page/; }
rewrite ^/blog/(.*)$ /articles/$1 permanent;

Option 3: PHP in your theme or a small plugin

For a handful of redirects on any server, a few lines of PHP work everywhere:

add_action( 'template_redirect', function () {
	$map = array(
		'/old-page/'    => '/new-page/',
		'/2019-offer/'  => '/offers/',
	);
	$path = wp_parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
	if ( isset( $map[ $path ] ) ) {
		wp_safe_redirect( home_url( $map[ $path ] ), 301 );
		exit;
	}
} );

This runs after WordPress loads, so it is slower than server rules, but it is portable and easy to read. wp_safe_redirect only allows redirects to your own site and allowed hosts, which prevents open-redirect abuse.

Build rules without typos

The redirect generator turns a list of old and new URLs into Apache, Nginx or PHP rules, escapes special characters and warns about chains. Paste a CSV of URLs from a migration spreadsheet and copy the result.

Test every redirect

  1. Open the old URL in a private window; you should land on the new one.
  2. Check the status code and the number of hops with the redirect checker. You want exactly one 301 to a page that returns 200.
  3. For many URLs, paste the list into the bulk redirect checker and export the results.

Avoid these problems

  • Chains. A → B → C wastes time and some signals. Point A straight at C.
  • Loops. A → B → A, often caused by overlapping HTTPS, www and trailing-slash rules.
  • Redirecting everything to the home page. Google treats irrelevant redirects like soft 404s.
  • Removing redirects too soon. Keep them for at least a year after a migration, longer for pages with many external links.
  • Forgetting internal links. Update links in menus and content to the new URLs so visitors do not go through a redirect at all.

After a migration

Submit the new sitemap in Search Console, use the Change of Address tool for domain moves, and watch the Pages report for “Not found (404)” errors over the following weeks. Fix new 404s with additional redirects where a sensible replacement exists.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *