How to Redirect URLs in WordPress Without a Plugin

WordPress database connection error

Every time you delete a page, change a post's URL slug, restructure your site navigation, or migrate from an old domain, you create broken links. Those broken links hurt user experience, waste Google's crawl budget, and lose the SEO value of inbound links.

The solution is a redirect — a server-side instruction that automatically forwards visitors and search engines from an old URL to a new one.

Most WordPress guides recommend the Redirection plugin for this. And Redirection is an excellent plugin. But there are good reasons to handle redirects without a plugin:

Minimise plugin count Redirects fire before WordPress loads Small number of permanent redirects Works even if WordPress breaks

This guide covers every method for adding redirects in WordPress without a plugin — with code examples for each approach.

Understanding Redirect Types

301 — Permanent
301 Redirect (Permanent)
  • The old URL has permanently moved
  • Transfers virtually all SEO equity (PageRank)
  • Browsers cache aggressively
  • Use for all permanent URL changes
302 — Temporary
302 Redirect (Temporary)
  • The old URL has temporarily moved
  • Does NOT transfer SEO equity
  • Browsers don't cache
  • Only for genuinely temporary situations
Always use 301 for permanent URL changes. Using 302 when you mean 301 is one of the most common SEO mistakes with redirects.
2
WordPress PHP Functions
functions.php or wp-config.php — More Flexible

For redirects handled within WordPress itself, use wp_redirect() with the template_redirect hook. This gives you access to WordPress conditional functions like is_page(), is_category(), is_user_logged_in().

Redirect in functions.php

PHP functions.php — Conditional redirects
function my_custom_redirects() {
    // Redirect old page to new page
    if ( is_page( 'old-page-slug' ) ) {
        wp_redirect( home_url( '/new-page-slug/' ), 301 );
        exit;
    }
    
    // Redirect old category archive to new page
    if ( is_category( 'old-category-name' ) ) {
        wp_redirect( home_url( '/new-category-page/' ), 301 );
        exit;
    }
}
add_action( 'template_redirect', 'my_custom_redirects' );
Always call exit after wp_redirect() — without it, PHP continues executing and the redirect may not fire.

Redirect by Post ID

PHP Redirect specific post by ID
function redirect_old_post() {
    if ( is_single( 123 ) ) { // Replace 123 with actual post ID
        wp_redirect( home_url( '/new-post-slug/' ), 301 );
        exit;
    }
}
add_action( 'template_redirect', 'redirect_old_post' );

Redirect Logged-In Users

PHP Conditional redirect by user status
function redirect_logged_in_users() {
    if ( is_page( 'login-page' ) && is_user_logged_in() ) {
        wp_redirect( admin_url() );
        exit;
    }
}
add_action( 'template_redirect', 'redirect_logged_in_users' );

Redirect via wp-config.php (Works Even If WordPress Breaks)

PHP wp-config.php — Fires before WordPress loads
// Add BEFORE require_once ABSPATH . 'wp-settings.php';
 $current_url = (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
if (strpos($current_url, 'olddomain.com') !== false) {
    $new_url = str_replace('olddomain.com', 'newdomain.com', $current_url);
    header("Location: $new_url", true, 301);
    exit;
}
Trade-off: PHP redirects are slightly slower than .htaccess (WordPress must load first) but give you access to WordPress's conditional logic — ideal for redirects that depend on user roles, page types, or categories.
3
Nginx Configuration
Nginx Servers — .htaccess Doesn't Apply

If your server runs Nginx instead of Apache (check in Tools → Site Health → Info → Server), .htaccess doesn't apply. Nginx uses its own server configuration file.

Nginx nginx.conf — Server block
server {
    # ... existing configuration ...
    
    # Single URL redirect
    location = /old-page/ {
        return 301 https://yourdomain.com/new-page/;
    }
    
    # Pattern-based redirect
    location ~ ^/old-section/(.*)$ {
        return 301 /new-section/$1;
    }
    
    # Full domain redirect
    server_name olddomain.com www.olddomain.com;
    return 301 https://newdomain.com$request_uri;
}
Note: On managed hosting (Cloudways, Kinsta), you typically can't edit nginx.conf directly — use the hosting dashboard's redirect feature or a Nginx directive field in your application settings.

When Should You Use a Plugin Instead?

Despite everything above, the Redirection plugin is often the right choice:

Use a Plugin When
  • Manage many redirects (10+) over time
  • Need audit log of redirects and 404 monitoring
  • Non-developers need to manage redirects
  • Import/export redirects from spreadsheet
  • Conditional redirects (referrer, device type)
Use .htaccess When
  • Maximum performance needed
  • Redirects must fire before WordPress loads
  • Small number of permanent redirects
  • Full domain migration
Use functions.php When
  • Need WordPress conditional checks
  • Already in custom plugin/theme workflow
  • Redirects depend on user roles or page types

Common Redirect Mistakes

Using 302 instead of 301 Always use 301 for permanent changes — 302 doesn't pass SEO equity.
Missing trailing slash If WordPress uses trailing slashes, include them: /old-page/ not /old-page.
Redirect chains A→B→C adds latency. Set direct 301s from A→C, eliminate B.
Redirect loops A→B→A = infinite loop. Always test redirects in a browser after adding them.
Not updating internal links Update your own internal links to point directly to the new URL — don't rely on redirects indefinitely.

Frequently Asked Questions

Q: How do I test that a redirect is working correctly?
A: Use a browser's developer tools (F12 → Network tab), load the old URL, and verify the Status column shows 301 (or 302). You can also use online redirect checker tools (e.g., httpstatus.io) to test any URL and see its full redirect chain.
Q: Do 301 redirects pass 100% of SEO value?
A: Google says 301 redirects pass "the vast majority" of link equity. The exact percentage has varied over the years in Google's communication — treat it as approximately 99% for practical purposes.
Q: How many .htaccess redirects is too many?
A: Apache processes .htaccess on every request, checking each rule in order. More than 100–200 redirect rules in .htaccess can create noticeable overhead. For large redirect lists (hundreds or thousands), use a database-driven solution like the Redirection plugin, which is more efficient at scale.

Final Thoughts

Redirects are a fundamental WordPress maintenance skill — every URL change without a redirect creates a broken link. The .htaccess method is the most performant for permanent redirects on Apache servers. PHP functions give you access to WordPress's conditional logic. And when redirect management becomes complex, the Redirection plugin is the right tool.

Master these techniques and you'll handle URL changes, site migrations, and content restructuring without SEO disruption or user frustration.

Contact us for professional WordPress development and SEO setup