How to Redirect URLs in WordPress Without a Plugin
Recent Posts
Digital Marketing Trends 2026: What Indian Businesses Must Know
Retargeting Ads Explained: How to Bring Back Lost Visitors (2026)
Marketing Funnel 2026: How Indian Customers Actually Buy Now
Performance Marketing Explained: CPL, ROAS, CAC for Indian Businesses
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:
This guide covers every method for adding redirects in WordPress without a plugin — with code examples for each approach.
Understanding Redirect Types
- The old URL has permanently moved
- Transfers virtually all SEO equity (PageRank)
- Browsers cache aggressively
- Use for all permanent URL changes
- The old URL has temporarily moved
- Does NOT transfer SEO equity
- Browsers don't cache
- Only for genuinely temporary situations
The .htaccess file is processed by Apache at the server level — before WordPress ever loads. Redirects added here fire faster than any plugin-based approach and impose zero PHP overhead.
Find and Edit .htaccess
wp-config.php).htaccess (enable hidden file viewing in your FTP client)Standard WordPress .htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# BEGIN WordPress block — not inside it.Single URL Redirects
# 301 redirects (add ABOVE # BEGIN WordPress)
Redirect 301 /old-page-slug/ https://yourdomain.com/new-page-slug/
Redirect 301 /another-old-url/ https://yourdomain.com/new-url/
# Redirect a renamed blog post
Redirect 301 /blog/old-post-title/ https://yourdomain.com/blog/new-post-title/
# Redirect a deleted page to the homepage
Redirect 301 /services/old-service/ https://yourdomain.com/
Redirect [type] [old-path] [new-full-URL] — old path is relative (starts with /), new URL is absolute (includes domain).Pattern-Based Redirects (RegEx)
# Redirect /old-section/ to /new-section/ preserving path
RewriteRule ^old-section/(.*)$ /new-section/$1 [R=301,L]
# Redirect old blog structure to new structure
RewriteRule ^blog/category/(.*)$ /articles/$1 [R=301,L]
# Redirect query string URLs to clean URLs
RewriteCond %{QUERY_STRING} ^p=([0-9]+)$ RewriteRule ^$ /%1/? [R=301,L]
Full Domain Redirect
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com [NC]
RewriteRule ^(.*)$ https://newdomain.com/$1 [R=301,L]
Non-www to www (or Vice Versa)
# Redirect www to non-www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.yourdomain\.com [NC]
RewriteRule ^(.*)$ https://yourdomain.com/$1 [R=301,L]
# Redirect non-www to www
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
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
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' );
exit after wp_redirect() — without it, PHP continues executing and the redirect may not fire.Redirect by Post 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
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)
// 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;
}
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.
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;
}
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:
- 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)
- Maximum performance needed
- Redirects must fire before WordPress loads
- Small number of permanent redirects
- Full domain migration
- Need WordPress conditional checks
- Already in custom plugin/theme workflow
- Redirects depend on user roles or page types
Common Redirect Mistakes
/old-page/ not /old-page.
Frequently Asked Questions
Q: How do I test that a redirect is working correctly?
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?
Q: How many .htaccess redirects is too many?
.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