How to add a 301 redirect in WordPress without a plugin

When one WordPress URL has moved permanently, a 301 redirect sends visitors and crawlers from the old address to the closest useful replacement. For example, /blog/old-post/ can point to /blog/new-post/. Google treats a permanent server-side redirect as a canonicalization signal, but it does not promise instant indexing or a complete transfer of search performance. Choose a destination that answers the same need. Do not send an unrelated URL to your homepage. Google: redirects
The right method depends on your host. First, check whether WordPress recognizes a renamed post. If it does not, look for a hosting redirect tool or confirm whether the server uses Apache or Nginx. Make a backup before adding one narrow rule. The examples use example.com as a canonical HTTPS placeholder. cPanel: redirects Apache: mod_rewrite NGINX: web server
Check WordPress before adding a rule
WordPress can remember an earlier slug when a published post that is not part of a page hierarchy is renamed. A slug is the final URL part after the domain, such as old-post in /blog/old-post/. WordPress first treats the request as a 404, then its old-slug check can look up that stored value and send a 301 to the current post. Test the old URL in a private browser window or with the header command shown later before adding another redirect. A working old-slug redirect means you may not need a server edit for that one post. WordPress: changed slugs WordPress: old-slug redirect
That behavior has narrow boundaries. It does not cover every page, content in a page hierarchy, deleted URL, arbitrary old path, domain move, or destination unrelated to the renamed post. Use an explicit mapping when the old address is not a simple published post slug change. This guide covers one old path and one relevant destination. WordPress: old-slug redirect
Try the host or cPanel tool
If your host provides a documented redirect screen, use it before editing a file. In cPanel, select a Permanent 301, choose the relevant domain, enter the source path after the domain, and provide the complete destination URL with its protocol. cPanel also provides a test link in the redirect table. Enter one old path and its closest replacement. cPanel: redirects
Make a timestamped copy of .htaccess before changing anything manually. cPanel says its interface writes generated rules at the bottom of that file. WordPress or another application can override or ignore a rule because of section order. A wildcard option can broaden a redirect beyond one old path, so leave Wild Card Redirect unchecked. If the dashboard rule does not run, inspect the generated file. In a root .htaccess, place the narrow rule before the # BEGIN WordPress managed block and preserve that block. Ask the host for help when you cannot safely change the order. cPanel: redirects cPanel: manual redirects
Not every WordPress host has cPanel or a redirect screen. If the tool is absent or offers only a broad wildcard option, use the server method that your host confirms. A full migration needs a wider URL map and cutover plan. A single rule does not cover a website migration to WordPress. cPanel: redirects
Add one exact Apache rule in .htaccess
Use this method only when your host confirms Apache or a compatible configuration that permits rewrite rules in .htaccess. You also need access to the correct document root and the required override settings. A root .htaccess file matches the path without its leading slash, so the pattern starts with blog. If WordPress is installed in a subdirectory, the rule location and matching path can differ. Ask the host before editing when either detail is unclear. Apache: mod_rewrite
After saving a copy outside the public web root where possible, place this narrow rule in the appropriate existing .htaccess location. Replace the host and destination with your own canonical HTTPS values. Keep the rule structure unchanged. Apache: mod_rewrite
RewriteEngine On
RewriteRule ^blog/old-post/?$ https://example.com/blog/new-post/ [R=301,L]
This maps /blog/old-post/ to /blog/new-post/. The /?$ allows the trailing slash to be present or absent while keeping the match exact. It will not match a child path such as /blog/old-post/extra or a sibling path. Query strings are not part of the pattern. With this absolute destination, Apache carries the original query string by default. If dropping parameters is deliberate and safe, use the optional form below instead. Apache: mod_rewrite
RewriteRule ^blog/old-post/?$ https://example.com/blog/new-post/ [R=301,L,QSD]
Use [QSD] only when you have decided that tracking or other query parameters should be discarded. Test that decision with a representative query string. Place the rule where the application's ordering requires it. Keep WordPress's existing rules. If the site is in a subdirectory, confirm how that directory prefix is handled before using the root example. Apache: mod_rewrite
A misplaced rule can leave the old URL returning 404. An HTTP 500 after the edit can indicate a syntax error or unsupported directive. Restore the known-good backup after an HTTP 500, then retest before another change. The supplied rule was checked in a disposable Apache 2.4.67 loopback fixture with static pages. That local check covered both slash forms, a sample query string, unmatched child and sibling paths, and a final local response with HTTP 200 after one redirect. It did not cover a WordPress runtime, cPanel server, Nginx configuration, or production host. Apache: mod_rewrite
Use the Nginx server block when required
Nginx does not read .htaccess. A server administrator or hosting provider must edit the active server block that serves the old public URL. Nginx selects that block using the listening address and port and the request host. Confirm the intended canonical host and HTTPS scheme before applying a rule. Keep the existing server block and unrelated locations intact. NGINX: web server NGINX: rewrite module
Inside the existing server block, use the concise exact-location form below. NGINX: rewrite module
location = /blog/old-post/ {
return 301 https://example.com/blog/new-post/;
}
The exact location above matches /blog/old-post/ with the slash. It does not automatically match /blog/old-post without it. Add a second exact location if both forms are intended, or ask the host to implement a deliberate normalization rule. Check the active host and resulting Location header after the configuration is reloaded. Do not paste this snippet into a WordPress admin screen. NGINX: web server Google: redirects
Test the redirect and know how to undo it
Use a header-only request to inspect the redirect response without the old page body. curl manual
curl -I https://example.com/blog/old-post/
You should see 301 and a Location header pointing to the intended destination. Location is the response field that tells the client where to go. Use the follow-up command below to expose every hop. curl manual
curl -IL https://example.com/blog/old-post/
The followed output exposes every hop. Check for one expected 301, no extra hops, and HTTP 200 at the intended final URL on the canonical host and scheme. Test /blog/old-post without the slash when both forms are meant to work. Add a representative query string when you need to confirm that parameters are retained or dropped. Request the destination directly. These commands check documented status and Location behavior. The site's production host was not tested. curl manual
Keep the timestamped .htaccess or Nginx configuration backup with the old-to-new mapping. Restore the backup after a 500, redirect loop, wrong host, wrong destination, or unexpected extra hop. Reload the Nginx configuration when applicable, rerun the one-hop checks, and change one variable at a time. If the host controls the server block or rule order, send the host the old URL, intended destination, response headers, and time of failure. Apache: mod_rewrite
Once the mapping is stable, update internal links and any sitemap entry that still names the retired URL. Google may recrawl at a different pace, so do not treat the redirect as a promise of an immediate search-result change. A broader crawl or indexability review may be appropriate when several old URLs, chains, or conflicting canonical signals remain. Google: redirects
Troubleshoot the specific failure
A 404 usually means the rule did not match the path, slash form, host, or rule location. Check the generated file and the path before changing syntax.
A 500 points to configuration syntax or an unsupported directive. Restore the timestamped backup first, then retest.
For a loop, follow the hops and look for a URL that repeats. An extra hop can indicate a separate HTTP-to-HTTPS or host-normalization redirect. An unexpected query string means the retention policy needs review. Ask the host to confirm the active server, document root, and rule order when those details are outside your access. cPanel: manual redirects Apache: mod_rewrite