WP 301 Redirect: How to Set Up 301 Redirects in WordPress (Plugin or .htaccess)
By Oktay BozacıPublished: 7 min read

A WP 301 redirect tells browsers and search engines that a page has moved to a new address for good. You can set one up in three ways inside WordPress: with a redirect plugin, with a rule in the .htaccess file on an Apache server, or with a PHP call in your own code. On an Nginx server, the same rule goes into the server configuration instead.
Redirects matter when a URL changes. Old links, bookmarks and search results still point to the old address. A 301 sends those visitors to the new page instead of an error page. Each method below comes with its exact syntax, and a testing section shows how to confirm the result.
Choosing a WP 301 redirect method
Pick the method that matches your server and how many URLs you need to move.
| Method | Works on | Best for | Main risk |
|---|---|---|---|
| Redirect plugin | Any host | One or a few URLs, no code | Overlapping rules |
.htaccess rule |
Apache servers | Single URLs and patterns | A syntax error can break the site |
| PHP in WordPress | Any host running WordPress | Redirects tied to your own code | Needs custom code |
| Nginx server block | Nginx servers | Sites hosted on Nginx | Needs server configuration access |
| Hosting panel or Cloudflare | Depends on the provider | Quick rules without server access | Extra layer, possible chains |
If you are not sure which server you run, check your hosting panel or ask your host.
Redirect one URL with a plugin
A plugin is the least technical option. Many SEO plugins also include a redirect module, so you may already have one installed.
- Install a redirect plugin, or open the redirect module of the SEO plugin you already use.
- Enter the old URL path as the source, for example
/old-page/. - Enter the full new address as the destination.
- Set the type to 301 (Permanent).
- Save the rule and test it, as described below.
Keep all redirects in one tool. Two plugins with rules for the same path can send a visitor through a chain or into a loop. Check the existing redirect list before you add a new rule.
Redirect with .htaccess on Apache
On Apache, the .htaccess file in the WordPress root folder holds redirect rules. WordPress writes its own block of rewrite rules into this file, so place your lines above that block.

The simplest form uses the Redirect directive:
Redirect 301 /old-page/ https://example.com/new-page/
If you omit the status argument, it defaults to 302 (temporary), so pass 301 explicitly.
For more control, use RewriteRule with the R and L flags. WordPress already enables the rewrite engine in its block, so you only need the rule line:
RewriteRule ^old-page/?$ https://example.com/new-page/ [R=301,L]
R=301 sets the status code. Without it, the default is 302. L tells Apache to stop processing the rule set after this match.
Apache checks Redirect lines in the order they appear, and the first match wins. Put specific rules above broad ones. A pattern can also match more paths than you intended. For example, this rule moves every URL under /blog/:
RedirectMatch 301 ^/blog/(.*)$ https://example.com/news/$1
Test a pattern on a few URLs before you rely on it. Also keep a copy of the original .htaccess file. A broken file can cause a server error across the whole site.
Redirect with PHP using wp_safe_redirect()
If you already maintain a small custom plugin, you can run the redirect in PHP. Wrap the check in a function and attach it with add_action() to the template_redirect hook, which runs before the page is output:
function my_old_page_redirect() {
if ( is_page( 'old-page' ) ) {
wp_safe_redirect( home_url( '/new-page/' ), 301 );
exit;
}
}
add_action( 'template_redirect', 'my_old_page_redirect' );
wp_safe_redirect() takes the status code as its second argument. Its default is 302, so pass 301 explicitly.
The function also checks the destination host. If the host is not on the allowed list, WordPress sends the visitor to the wp-admin area of your site instead. For a redirect to another domain, use wp_redirect() and keep the exit; after it.
Redirect on Nginx
On Nginx, put the rule in the server block for your site. The permanent flag of the rewrite directive returns a 301 response:
rewrite ^/old-page/?$ https://example.com/new-page/ permanent;
Reload Nginx after you save the change. Nginx does not read .htaccess files, so a rule placed there has no effect.

Old slugs that WordPress redirects on its own
When you change the slug of a post, WordPress can send the old slug to the current permalink. The core function wp_old_slug_redirect() handles this case.
This built-in behavior has limits. It covers the slug change you made. It does not replace a rule for a page you deleted or for a page you moved to a different URL structure. Those still need an explicit redirect. Confirm the actual status code with curl, as shown in the testing section.
Status codes: 301, 302, 307 and 308
| Code | Meaning | Use it when |
|---|---|---|
| 301 | Moved permanently | A page has a new permanent address |
| 302 | Moved temporarily | A short-term change. This is the default for Apache Redirect without a status, R without a code, and wp_safe_redirect() |
| 307 | Temporary, method kept | A temporary change where the request method must stay the same |
| 308 | Permanent, method kept | A permanent move where the request method must stay the same |
For most page moves, the 301 is the right choice. For a deeper comparison of the two most common codes, read 301 vs 302 redirects.

Choosing the destination
Send each old URL to the closest matching new page. Sending every removed page to the homepage is a common shortcut, but visitors who land there lose the topic they came for. If no relevant page exists, the homepage can be a fallback.
Update your internal links so they point to the new address. Otherwise, visitors and crawlers pass through a redirect every time they follow an old link.
When you move a whole domain, map the old URLs one by one where you can. A single catch-all rule is easier to write, but it sends every path to one place.
Keep the 301 in place for as long as old links and bookmarks still bring visitors. There is no fixed date after which it should be removed.
Test the redirect
Use curl to read the response headers without loading the page in a browser:
curl -I https://example.com/old-page/
A working redirect returns a status line with 301 and a Location header that holds the new address:
HTTP/1.1 301 Moved Permanently
Location: https://example.com/new-page/
If the status is 302, check the rule for a missing 301. To follow the full path, add -L:
curl -IL https://example.com/old-page/
This shows the status and Location header for each hop. A 301 can usually be cached by the browser, and caching behavior varies, so test in a private window or with curl to avoid stale results.
Loops, chains and layer conflicts
A redirect loop happens when two rules send a URL back and forth, or when the HTTP and HTTPS settings point in a circle. The browser then stops with an error such as too many redirects.
A chain is a series of redirects, for example old URL to intermediate URL to final URL. Each hop adds a request and slows the visit. Replace the chain with one direct redirect to the final address.

A site can hold redirect rules in several places: the WordPress plugin, the .htaccess file or server configuration, and Cloudflare Redirect Rules. When a redirect behaves oddly, check every layer. A rule at one layer can make a rule at another layer look as if it does nothing.
Choose one preferred address, such as HTTPS with or without www, and redirect the other variants to it with one rule. Without that, each variant can lead to a different copy of the page.
Common mistakes
- Leaving out the status code. Apache
Redirect,RewriteRulewithRandwp_safe_redirect()all default to 302, so a permanent move ends up temporary. - Putting a broad rule above a specific one. Apache uses the first match.
- Defining the same redirect in a plugin and in
.htaccess, which makes loops and chains hard to trace. - Sending every removed page to the homepage instead of the closest matching page.
Quick checklist
- Back up
.htaccessif you edit it, and note the old URL with its closest new destination. - Add the rule with a 301 status in one place only.
- Run
curl -Iand confirm both the 301 status and theLocationheader. A 302 means the rule is missing its 301. - Use 302 only when the move is temporary.
- Update internal links and check for chains or loops.
Sources
- Apache Module mod_alias — Apache HTTP Server Project
- RewriteRule Flags — Apache HTTP Server Project
- Module ngx_http_rewrite_module — nginx
- wp_safe_redirect() – Function | Developer.WordPress.org — WordPress Developer Resources
- wp_old_slug_redirect() – Function | Developer.WordPress.org — WordPress Developer Resources
Related posts
301 vs 302 Redirect: Which One Should You Use for SEO?
Use a 301 for permanent moves and a 302 only when the original URL should come back. See how each code affects search engines, and when to use 503 instead.
· 5 min read
Best Tags for YouTube Videos: How to Find and Add Them
The best tags for YouTube videos describe what your video covers. Learn how to find them with Trends, add them in Studio, and avoid common mistakes.
· 5 min read
How to Get a YouTube Thumbnail from a Video URL
Copy the video link, find the video ID, then open or grab the thumbnail image. Learn the steps, what to do when the image does not load, and when reuse needs permission.
· 5 min read
How to Create an XML Sitemap and Submit It to Google
Learn how to create an XML sitemap, choose the right URLs, check the file, and submit it to Google Search Console.
· 8 min read



