Yes, fixing a WordPress redirect loop after migrating your site is straightforward if you identify the root cause—usually broken permalinks, incorrect rewrite rules, or database inconsistencies. The fix involves checking your WordPress configuration, database tables, and ensuring nothing in your `.htaccess` file or `wp-config.php` is forcing unwanted redirects. If those don’t work, you may need to temporarily disable plugins or revert to default permalinks to isolate the issue. Here’s how to proceed step-by-step, backed by real fixes applied by WordPress users worldwide.
What You'll Need
- A live server or staging environment where you can safely test changes (avoid affecting your production site until you confirm fixes work).
- Access to your WordPress database (via phpMyAdmin or tools like WP-CLI).
- The ability to edit your site’s `.htaccess` file (located in your WordPress root directory).
- An FTP client or file manager (like FileZilla) to upload or modify files.
- A backup of your database and files before making critical changes.
- SSH access (if your host requires it for editing `.htaccess` or database commands).
Step-by-Step
- Check Permalinks Settings WordPress automatically generates rewrite rules for permalinks. After migration, these may break due to incorrect settings. Go to Settings > Permalinks in your WordPress dashboard and click Save Changes. This forces WordPress to regenerate rewrite rules, which resolves most redirect loops caused by mismatched settings. If you’re using a custom plugin like Yoast SEO or Rank Math, ensure their permalink settings are compatible with your migration.
- Inspect the .htaccess File
Open your WordPress root folder via FTP or SSH and locate the `.htaccess` file. Look for lines resembling these, which are often misconfigured after migration:
RewriteBase / RewriteRule ^index\.php$ - [L]If these are missing or incorrect, edit the file to ensure it includes:# BEGIN WordPressIf your host blocks `.htaccess` editing, contact support to temporarily enable it for testing.RewriteEngine On RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] # END WordPress - Reset WordPress Rewrite Rules
If the loop persists, the rewrite rules in your database may conflict. Use one of these methods:
- Method 1: Use a Plugin Install the Search Rewriting plugin, go to Settings > Search Rewriting, and click Reset Rewrite Rules. This clears all rewrite rules without data loss.
- Method 2: Manually via phpMyAdmin
Open your WordPress database in phpMyAdmin and delete these tables:
wp_options (filter = 'rewrite_rules')Then re-run Settings > Permalinks > Save Changes to regenerate rules.
- Disable Plugins Temporarily Many plugins introduce redirect loops if their settings weren’t migrated correctly. Deactivate all plugins via FTP or your hosting control panel (not the dashboard) and test if the loop disappears. Reactivate them one by one until you find the culprit. Note: For security, disable plugins via your server (not the web interface) to avoid exposing your site to brute-force attacks.
- Check for Custom Rewrite Rules
If you added or modified rewrite rules in your theme’s `functions.php` or via custom code, remove them. Look for lines like:
add_rewrite_rule('^some-custom-path/$', 'custom_function', 'top');If you suspect a misplaced rule, revert or comment out the file via FTP. - Verify Database Consistency
After migration, some database tables may reference old URLs. Run these queries via phpMyAdmin to clean them up:
- Update URLs in the `wp_posts` table:
UPDATE wp_posts SET guid = CONCAT('https://', GET_HOST_FROM_CONTEXT(), '/', post_name), post_content = REPLACE(post_content, 'old-url/', ''); - Update URLs in `wp_links` (for external links):
UPDATE wp_links SET url = REPLACE(url, 'old-domain.com', 'new-domain.com');
- Update URLs in the `wp_posts` table:
- Force Default Permalinks As a last resort, switch to the plain URL structure (Settings > Permalinks > Common Format) and save. This bypasses rewrite rules entirely. Once the loop is fixed, switch back to your preferred permalink structure.
If That Did Not Work
Try these advanced steps in order:- Check Server-Level Redirects
Search your server’s root directory for files like `robots.txt`, `.htaccess`, or server-side config files (e.g., Apache/Nginx) that might redirect traffic. For example, Nginx may have a rule like:
return 301 /index.html;which could conflict with WordPress. Disable or comment out such rules temporarily. - Use .htaccess Debugging Mode
Temporarily add this to your `.htaccess` to log rewrite errors:
ErrorLog /path/to/error.log RewriteLog /path/to/rewrite.log RewriteLogLevel 3Check the log file for clues about which rule is causing the loop. - Switch to a Staging Site If your live site is still unstable, migrate to a staging environment and repeat the troubleshooting steps. If the loop appears there, the issue is likely with your hosting or migration process.
- Reinstall WordPress (Last Resort)
If all else fails, reinstall WordPress on a clean copy of your files and migrate your content manually. This requires:
- Downloading your database via phpMyAdmin (export as SQL).
- Importing it into the new WordPress installation (use the "Import" option in phpMyAdmin).
- Updating all URLs in `wp_posts` and `wp_options` manually (as shown above).
Common Mistakes
- Skipping Permalinks After Migration Many users forget to regenerate rewrite rules after updating permalinks. Always save changes in Settings > Permalinks post-migration.
- Editing .htaccess Without Backup Misconfiguring `.htaccess` can break your site. Always back up files before editing.
- Ignoring Plugin Conflicts Newly installed or misconfigured plugins can trigger loops. Disable them one by one to identify the offender.
- Not Verifying Database Changes If you manually update URLs in `wp_posts` or `wp_links`, ensure all entries are corrected. A single misplaced URL can cause the loop.
Tips
- Use a Migration Plugin for Safer Transfers Tools like All-in-One WP Migration or Duplicator handle permalinks and rewrite rules automatically during migration.
- Test Redirects with Browser DevTools Open DevTools (F12) in Chrome/Firefox, go to the "Network" tab, and reload the page. Look for 301/302 redirects—if they’re looping, the issue is in rewrite rules.
- Avoid Custom Code During Migration If you modified `functions.php` or added plugins, test them only after confirming the site works without loops.
- Clear Cache After Changes If caching plugins (like WP Super Cache) are enabled, clear their cache after adjusting rewrite rules to ensure changes take effect.
- Use WP-CLI for Database Tasks
If you’re comfortable with the command line, run WP-CLI commands like:
wp option update rewrite_rules_base /to force correct rewrite rules without editing files manually.
Troubleshooting
- The Loop Persists After All Fixes Contact your hosting provider to check for server-side redirects (e.g., Nginx/Apache rules) that might interfere. They can provide access to server logs for debugging.
- You Don’t Have SSH or FTP Access Use your hosting’s control panel (e.g., cPanel) to edit `.htaccess` or access phpMyAdmin. Some hosts provide one-click database exports/imports via the dashboard.
- You’re Using a Managed Host (e.g., WP Engine) Managed hosts often handle rewrite rules via their control panel. Check for a "Re-Apply Rewrite Rules" option in their dashboard.
- The Loop Only Happens on Certain Pages Use browser DevTools to inspect the HTTP response headers for those pages. Look for `301` or `302` redirects, which may point to a specific plugin or custom rule.
Frequently Asked Questions
Why does my WordPress site keep redirecting after migration?
A redirect loop after migration typically occurs because permalinks weren’t regenerated, rewrite rules in `.htaccess` are misconfigured, or database entries still reference old URLs. The simplest fix is to run Settings > Permalinks > Save Changes and check for plugin conflicts.
How do I force WordPress to ignore rewrite rules temporarily?
Switch to the plain URL structure (Settings > Permalinks > Common Format). This forces WordPress to use flat URLs instead of rewrite rules, bypassing the loop. Once resolved, switch back to your preferred permalink structure.
Can I fix this without accessing the database?
Yes! Start with Settings > Permalinks > Save Changes, then check `.htaccess` for errors. If plugins are the issue, disable them one by one. Only database steps are necessary if the loop persists after these checks.
What if my host blocks .htaccess editing?
Contact your host to temporarily enable the file. If that’s not possible, use a plugin like Search Rewriting to reset rewrite rules or switch to plain URLs.
How do I know if a plugin is causing the redirect loop?
Disable all plugins temporarily. If the loop disappears, reactivate them one by one until you find the culprit. Plugin logins or configuration errors often cause such issues.
Is there a way to check which rule is causing the loop without editing files?
Use browser DevTools to inspect the HTTP headers for each page. Look for `301` or `302` redirects. If the loop occurs for every page, the issue is likely in rewrite rules or permalinks. If it’s page-specific, the redirect may come from a custom rule or plugin.