Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk10 min

How to Create a Redirect in WordPress (301, 302, PHP, Apache, Nginx, and Plugin Methods)

Create reliable WordPress redirects with the right 301 or 302 status. Follow step-by-step plugin, PHP, Apache, and Nginx instructions, then verify, troubleshoot, and roll back safely.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To redirect a WordPress URL, send the old address to the new one with a permanent 301 status when the move is final, or a temporary 302 while you are testing or expecting the old address to return. You can create the rule in a dashboard plugin, PHP, Apache’s .htaccess file, or an Nginx server block. The best method depends on the access you have and whether you need conditional logic, logs, or server-level performance.

This guide shows each approach, explains the safety details that prevent broken redirects and open-redirect vulnerabilities, and gives a verification and rollback process.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the redirect type before creating the rule

A redirect is an HTTP response telling a browser or crawler to request another URL. The response includes a status code and a Location destination. Selecting the status code first prevents a temporary experiment from being treated as a permanent site change.

301: permanent move

Use a 301 when the old URL has been replaced and should remain replaced. Typical cases include changing a page slug, consolidating duplicate URLs, moving content to a new section, or switching a site to a canonical HTTPS URL. The old address should continue redirecting for as long as visitors and external links may still use it.

302: temporary move or test

Use a 302 while a destination is temporary, a campaign is running, or you are testing a new page before deciding whether the move is permanent. WordPress’s wp_redirect() function defaults to 302 unless you pass another 3xx status.

Other codes available in the Redirection plugin

The Redirection plugin’s WordPress.org listing says it supports 301, 302, 303, 304, 307, and 308 responses. Most page moves need 301; most short-lived tests need 302. Use the other codes only when their specific HTTP behavior is part of your design.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Pick the implementation method

Method Access needed Best for Important trade-off
Redirection plugin WordPress administrator access Editors managing many rules, 404 monitoring, and regular expressions Another plugin handles every request that matches its rules
PHP Ability to deploy a custom plugin or edit a controlled theme Conditional redirects based on WordPress logic Runs through WordPress and requires careful code and termination
Apache .htaccess Access to the site’s Apache configuration file Simple rules that should run before WordPress A syntax error can affect the whole site; back up first
Nginx server configuration Host or server deployment access Fast server-level rules on Nginx Exact file location and reload procedure vary by host

Server-level rules are evaluated before WordPress loads, while PHP and plugins can use WordPress context such as page conditions. A plugin is generally the least technical route and offers logs; PHP offers precise conditions; Apache and Nginx are portable only within their respective server environments.

Method 1: Create a redirect with the Redirection plugin

Use this method when you can administer WordPress but do not want to edit PHP or server configuration. The official WordPress.org listing describes Redirection as free software with dashboard rules, 404 logs, regular expressions, permalink migration, and Apache and Nginx export.

Install and open the redirect manager

  1. Sign in to WordPress with an account allowed to install plugins.
  2. Go to Plugins → Add New.
  3. Search for Redirection, verify that it is the plugin published on WordPress.org, then install and activate it.
  4. Open the plugin’s setup screen and complete its initial configuration. If it offers to monitor 404 errors, enable that option when you want the plugin to record missing URLs.

Add a basic old-page-to-new-page rule

  1. Open the plugin’s redirect screen, usually available under Tools → Redirection after activation.
  2. Enter the old path as the source, such as /old-page/. In a normal WordPress installation, enter the path rather than duplicating the full domain.
  3. Enter the destination URL, such as /new-page/, or provide a complete URL when the destination is on another host.
  4. Select 301 – Moved Permanently for a final move, or 302 – Found for a temporary test.
  5. Save the rule, then request the old URL in a private browser window or with an HTTP client.

Use one canonical spelling for the destination. Decide whether it should use HTTPS and whether it ends with a slash, then make that exact form the target. A redirect that lands on another redirect creates a chain that is harder to debug and slower for visitors.

Use regular expressions only when the pattern is intentional

Regular expressions can redirect a family of old paths, but an overly broad pattern can capture administrative, media, or unrelated URLs. Build and test the narrowest expression that covers the required paths. Test a representative URL from every branch before publishing the rule.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use 404 logs to find missed URLs

After a migration, review the plugin’s 404 log for old links that were not covered. Confirm that each missing path should redirect before adding a rule; some requests are scans or genuinely invalid addresses that should remain 404 responses. The same dashboard can also export Apache .htaccess or Nginx rules when you later move logic to the server.

Method 2: Add a redirect in PHP

PHP is appropriate when the destination depends on WordPress conditions, such as a specific page, post state, or request context. Put the code in a small custom plugin when possible so it survives a theme change. Editing a parent theme’s file can lose the rule during an update.

Local destination with wp_safe_redirect()

Use wp_safe_redirect() when the destination should be local or could be influenced by request data. WordPress validates the destination host against allowed hosts and falls back if the URL is unsafe.

<?php
if ( is_page( 'old-page' ) ) {
    wp_safe_redirect( home_url( '/new-page/' ), 301 );
    exit;
}

The condition checks for the old page, home_url() builds a destination on the site’s configured home host, and the second argument sets the permanent status. Keep the final exit;: the official WordPress developer reference warns that “wp_redirect() does not exit automatically, and should almost always be followed by a call to exit;”. Without termination, WordPress can continue rendering the original request and emit additional output.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Hard-coded external destination with wp_redirect()

For a deliberately hard-coded external destination, use wp_redirect() and pass the status explicitly:

<?php
if ( is_page( 'old-page' ) ) {
    wp_redirect( 'https://example.com/new-page/', 301 );
    exit;
}

Do not pass an untrusted query-string value directly to wp_redirect(). If users, imported data, or request parameters can influence the target, validate the host and prefer wp_safe_redirect() for local destinations.

Where the PHP condition should run

Redirect logic must execute before the response body is sent. A custom plugin is a practical location because it loads independently of the active theme. If you place the logic in a theme, use a controlled theme or child theme and test after updates. Avoid inserting redirect code into a page’s visible content; by then WordPress has already begun producing the response.

Method 3: Add a redirect in Apache .htaccess

Apache can redirect before WordPress processes the request. This is useful for simple path changes and large sets of static rules. WordPress uses .htaccess as Apache’s per-directory configuration file and documents rewrite rules for WordPress installations.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Back up the file and preserve WordPress’s block

  1. Make a copy of the existing .htaccess file before editing.
  2. Open the file in your host’s file manager, SFTP client, or deployment system.
  3. Keep the existing section between # BEGIN WordPress and # END WordPress intact unless you know exactly why it must change.
  4. Place custom redirect rules before the WordPress catch-all rewrite block so the specific rule is evaluated first.

Use a specific rule

RewriteEngine On
RewriteRule ^old-page/?$ /new-page/ [R=301,L]

In this example, the optional slash allows both common forms of the old path, R=301 sends a permanent response, and L stops Apache from evaluating later rules for that request. The pattern is relative to the directory containing .htaccess, so do not automatically prepend the full domain or the directory prefix.

Change the rule for a temporary test

Replace R=301 with R=302 while the move is temporary:

RewriteRule ^old-page/?$ /new-page/ [R=302,L]

Once the destination is confirmed and the move is final, change it to 301 and retest from a clean session. Browsers and intermediate caches can retain redirect responses, which can make a corrected rule appear unchanged.

Method 4: Add a redirect in Nginx

Nginx uses server configuration rather than Apache’s .htaccess. The exact file and server block depend on the hosting provider’s deployment process. Make the change through that process, validate the configuration, and reload Nginx safely rather than editing an unknown production file.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Basic permanent rule

rewrite ^/old-page/?$ /new-page/ permanent;

The expression matches the old path with or without its trailing slash, and permanent produces a permanent redirect. A temporary test can use redirect instead, according to the host’s supported configuration conventions.

Export rules from the dashboard when server access is limited

The Redirection plugin documents Nginx export. You can create and test rules in the dashboard, export the resulting configuration, and provide it to the person or process that manages the Nginx server. Do not paste an Apache rule into Nginx; the syntaxes are different.

Redirect security and correctness checks

Prevent open redirects

An open redirect accepts an attacker-controlled destination and sends visitors away from your site. This can make a trusted URL appear to lead to a phishing page. Keep destinations fixed where possible. When input must influence a local redirect, use wp_safe_redirect() and ensure the allowed-host configuration reflects the hosts you genuinely control.

Keep one hop to the final URL

Map the old address directly to the final canonical address. Avoid sequences such as old HTTP URL → temporary URL → HTTPS URL → final slug. Chains complicate troubleshooting and can delay the visitor’s arrival. If several historical URLs point to the same content, each can target the final URL directly.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Do not create loops

A loop occurs when the source and destination eventually point back to each other. Common causes include a rule that matches both old and new slugs, conflicting slash rules, and broad regular expressions. Test the destination independently and inspect every rule that could match it.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Verify a redirect before announcing the change

  1. Request the old URL with an HTTP client or browser and confirm the expected status, such as 301 or 302.
  2. Inspect the Location header and confirm the exact scheme, host, path, capitalization, and trailing-slash form.
  3. Follow the destination and confirm that it returns the expected page rather than another redirect.
  4. Test both the old and new forms with and without a trailing slash when your rule is intended to support both.
  5. Check logged-in and logged-out behavior if the PHP condition depends on account state, cookies, or WordPress logic.
  6. Review 404 logs after publishing and add only the missing-path rules that represent real content or useful legacy links.

For a command-line check, use an HTTP client that shows headers and does not hide redirects. A single request should show the status and Location; a follow-up request should confirm the final response. If a browser keeps showing an old result after a correction, test in a private window and clear relevant caches.

Troubleshoot common failures

The old page still loads

  • Confirm the rule is active and saved in the correct environment.
  • Check that the source includes the right path and, for server rules, the correct directory-relative pattern.
  • Look for a later rule or WordPress catch-all that runs first; move a specific Apache rule above the catch-all.
  • Test the exact hostname and HTTPS variant being requested.

The site returns a server error

  • Restore the backed-up .htaccess file if the error began after an Apache edit.
  • Check Apache syntax or ask the host to validate the configuration.
  • For Nginx, use the host’s configuration-test and reload procedure instead of repeatedly reloading an invalid file.
  • For PHP, remove syntax errors and verify that the redirect code runs before output.

The redirect loops

  • Compare the source and destination character by character.
  • Disable overlapping rules temporarily and re-enable them one at a time.
  • Check whether an HTTPS, hostname, or slash-normalization rule sends the destination back to the source.
  • Ensure a regular expression does not match the new path as well as the old one.

The browser reports an unsafe or malformed destination

  • Confirm the destination is a complete, correctly encoded URL when it is external.
  • Remove user-controlled destination parameters.
  • For local PHP redirects, construct the target with home_url() and use wp_safe_redirect().

Changing, removing, and rolling back a redirect

Plugin rule

Edit or disable the rule in the Redirection dashboard, then retest the source URL. Keep a record of the previous target and status so you can restore it if traffic or an integration still depends on the old mapping.

PHP rule

Deploy the code change through the same version-controlled process used for the rest of the site. Remove or alter the condition, deploy, and test both the former source and the intended destination.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Apache or Nginx rule

Restore the backed-up configuration or revert the deployment, validate the server configuration, reload it through the host’s supported process, and request the old URL again. A rollback should remove the rule cleanly rather than adding a second rule that competes with it.

Practical decision guide

  • Choose the plugin when you need a dashboard, 404 logs, regular expressions, or many editor-managed mappings.
  • Choose PHP when the destination depends on WordPress conditions and you can safely deploy code.
  • Choose Apache when the site runs Apache and you need simple rules to execute before WordPress.
  • Choose Nginx when the host manages Nginx and server-level redirects belong in its deployment configuration.

Whichever method you use, decide whether the move is permanent, send visitors directly to the final canonical URL, validate destinations, and verify the actual status and Location response before considering the change complete.

Frequently Asked Questions

Can I redirect an old WordPress page to a new page without changing the old page’s content?

Yes. A redirect rule handles the old URL before or during request processing, so the old page does not need to remain publicly rendered. Keep the rule as long as visitors or links may still use the old address.

Why does WordPress return a 302 when I expected a 301?

`wp_redirect()` defaults to 302. Pass `301` as the second argument, or select the 301 response in your redirect plugin. Then verify the actual status with an HTTP client.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Which option should I use if I cannot edit PHP, Apache, or Nginx?

Use the Redirection plugin from the WordPress.org directory. It provides dashboard rules and can record 404 requests for later review.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

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

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.