You clone your production database over to a staging subdomain, hit enter in your browser, and get immediately bounced right back to your live site. It’s frustrating, and worse, it’s genuinely dangerous. If you click into /wp-admin thinking you’re in a sandbox while WordPress quietly routed you to production, you can end up blowing away live customer data, theme settings, or live orders. I ran into this exact mess last week while testing a payment gateway refactor.
Here is how to track down the redirect chain with cURL and step through database fixes, config overrides, rewrite rules, and persistent cache collisions until staging actually stays on staging.

Inspect the HTTP Redirect Chain with cURL
Don’t touch code or database rows yet. First, figure out what layer is throwing the redirect. Browsers aggressively cache 301s on disk, which means you’ll waste twenty minutes debugging a problem you already fixed five minutes ago.
Fire off a trace against your staging URL in your terminal using cURL to see every response code, header, and target location:
curl -IL https://staging.example.comA misconfigured clone usually spits back an instant 301 Moved Permanently or 302 Found sending you to production:
HTTP/2 301 location: https://example.com/
server: LiteSpeed
x-redirect-by: WordPressPay close attention to x-redirect-by. If it says WordPress, PHP spun up cleanly, but core canonical routines or an SEO/redirect plugin decided you belong on the live domain. If that header isn’t there and the server banner reports Nginx, LiteSpeed, or Apache, your web server or .htaccess is bouncing the request before WordPress even boots.
Check and Update the wp_options Table
Nine times out of ten, the database simply still thinks it’s production. When you clone a live database, two rows in wp_options keep pointing to the live domain: siteurl and home.
If you’ve got SSH access, hop into the staging docroot and use WP-CLI to check what’s stored:
wp option get siteurl
wp option get homeIf those print out https://example.com, point them to your staging subdomain right away:
wp option update siteurl "https://staging.example.com"
wp option update home "https://staging.example.com"If you’re stuck using phpMyAdmin or Adminer, run this query directly against the staging database (swap out the wp_ prefix if yours is different):
UPDATE wp_options SET option_value = 'https://staging.example.com' WHERE option_name IN ('siteurl', 'home');If you just created the subdomain, double-check that your DNS record actually points to the right server IP. Our guide on how to set up a WordPress staging site on Hostinger and deploy changes walks through verifying subdomain records.
Hardcode URLs in wp-config.php for an Instant Override
If you run deployment scripts that regularly sync down live database dumps, updating wp_options on every sync gets old fast. You can bypass database lookups entirely by forcing runtime constants in wp-config.php.
Drop these two lines near the top of your staging wp-config.php, right before the /* That's all, stop editing! */ comment:
define('WP_HOME', 'https://staging.example.com');
define('WP_SITEURL', 'https://staging.example.com');As covered in the WordPress wp-config.php documentation, these constants don’t overwrite database rows. They intercept calls to get_option(‘siteurl’) and get_option(‘home’) and return the strings directly, shutting down the core canonical redirect.
One caveat: if your staging site sits behind an SSL reverse proxy or Cloudflare Flexible SSL, setting this can trigger an infinite redirect loop (ERR_TOO_MANY_REDIRECTS). If that happens, stick this proxy check right above the URL definitions:
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { $_SERVER['HTTPS'] = 'on';
}If you run into certificate handshake failures while sorting this out, read through our guide to fix SSL certificate errors on a subdomain in Hostinger.
Run a Safe Search-Replace on Serialized Strings
Fixing siteurl and home stops the homepage from redirecting, but your staging site will still pull stylesheets, scripts, and internal links from production. Worse, page builders like Elementor store layout JSON and PHP serialized arrays full of the live URL.
Never run a raw SQL UPDATE ... REPLACE() across a WordPress database. Serialized strings store character lengths, like s:19:"https://example.com". If you swap that to https://staging.example.com without updating the length count from 19 to 27, PHP chokes and drops the serialized array entirely. Your layouts and customizer settings will vanish.
Run a dry run with WP-CLI first to see what’s actually affected:
wp search-replace "https://example.com" "https://staging.example.com" --dry-runIf the replacement counts look sane, run it for real and clear the cache in one go:
wp search-replace "https://example.com" "https://staging.example.com" --all-tablesWithout shell access, use the Better Search Replace plugin or the standalone interconnect/it Search Replace DB script. Both safely unpack serialized data, rewrite the string, update the length integers, and re-serialize.
Inspect .htaccess Rewrite Rules and Hardcoded Redirects
If your initial cURL trace showed a 301 without the x-redirect-by: WordPress header, Apache or LiteSpeed is firing the redirect before PHP ever touches the request. That almost always means you copied over your live .htaccess file along with all its hardcoded canonical rules.
Open .htaccess in your staging root and look for domain-specific enforcement rules:
# Broken rule cloned from live site
RewriteCond %{HTTP_HOST} !^example.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]Comment those out or delete them. If you’re not sure which custom rule is doing it, replace the whole file temporarily with the default WordPress rewrite block:
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPressSave and run cURL again. Getting rid of stale server-level rewrites fixes the bounce immediately in most cases.
Flush Persistent Object Cache and Redis Drop-Ins
This one burned two hours of my afternoon once: clean database, stock .htaccess, and staging still redirected to live. The issue was an object cache drop-in copied over from production that was connected to a shared Redis instance.
Look in wp-content/ for an object-cache.php file. If staging shares a Redis or Memcached daemon with live and uses the exact same database index and cache key prefix, staging simply reads the live options cached in memory.
Check your staging wp-config.php to see if a separate cache prefix or database number is configured:
// Ensure staging does not share cache keys with live
define('WP_CACHE_KEY_SALT', 'staging_');
define('WP_REDIS_DATABASE', 2);To verify if the object cache is causing the redirect, temporarily rename the drop-in file:
mv wp-content/object-cache.php wp-content/object-cache.php.bakThen flush the cache:
wp cache flushIf you’re on a LiteSpeed stack, clear wp-content/litespeed/ or purge it via your control panel. Check out our breakdown on how to reduce WordPress TTFB on Hostinger with LiteSpeed Cache for a closer look at how transients and cached options behave across cloned environments.
Fix Canonical Redirections Caused by Plugins
Certain plugins don’t care what’s in wp_options; they maintain their own domain settings in separate tables or options. Redirection plugins, security suites, and SEO plugins are notorious for this.
To see if a plugin is the culprit, turn all of them off at once using WP-CLI:
wp plugin deactivate --allHit the staging URL in a private browser window. If it loads properly on staging, turn your plugins back on one by one until the redirect resurfaces:
wp plugin activate --all
wp plugin deactivate redirection
wp plugin deactivate seo-by-rank-mathThe Redirection plugin is an easy culprit to spot: check Tools > Redirection > Options for a “Site URL” or “Default URL” setting. If it was copied from prod, it will ruthlessly bounce any hostname that doesn’t match the live domain. Update or clear it.
If the redirect is gone but styles are broken or assets won’t load, you’re probably dealing with mixed content. Follow our steps to fix WordPress mixed content warnings after SSL to track down rogue HTTP URLs.
Frequently Asked Questions
Why does my browser still redirect to live after I fixed the database?
Your browser cached the HTTP 301 redirect locally. It doesn’t even send a request to your server anymore—it just sends you straight to live from disk cache. Test using curl -IL https://staging.example.com, open an Incognito window, or pop open Chrome DevTools and check the Disable cache box in the Network tab.
Can I define WP_HOME and WP_SITEURL dynamically in wp-config.php?
Yes, by grabbing the host directly from the HTTP request headers:
define('WP_HOME', 'https://' . $_SERVER['HTTP_HOST']);
define('WP_SITEURL', 'https://' . $_SERVER['HTTP_HOST']);It works fine for quick browser testing, but watch out: $_SERVER['HTTP_HOST'] won’t exist when running commands via WP-CLI or server-side crons, which will break CLI operations.
Why does only /wp-admin redirect to the live site while the frontend works?
That means home was updated, but siteurl still points to production. WordPress relies on siteurl to resolve the admin panel, REST endpoints, and admin-ajax. Both settings must match your staging domain.
Will changing staging URLs affect my production website?
Only if your staging wp-config.php is accidentally connected to your live database. Always verify DB_NAME, DB_USER, and DB_HOST in staging before running search-replace operations.
What to Test Next
Once your staging site stays put, run a quick sanity check across key templates—homepage, a single post, and checkout/forms. Open the browser console to ensure scripts, web fonts, and AJAX endpoints aren’t still reaching out to your live production domain in the background.
If you’re using this staging environment to test new themes or layout imports, take a look at our guide on how to install Envato WordPress themes and demo content via WP-CLI to save time and avoid PHP timeout headaches.

