Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
Wordpress

WordPress: Fix Multisite Subdomain Mapping to the Wrong Blog

- 19.11.26 - ErcanOPAK

📝 Fix Multisite Subdomain Mapping to the Wrong Blog

A WordPress Multisite network running subdomain installs resolves each incoming request to a blog_id through a lookup that gets cached in the “blog-lookup” object cache group. When a site’s domain mapping changes — a new primary domain, an updated DNS record, or a direct database edit to wp_blogs/wp_site outside of WordPress’s own site-update functions — a Redis or Memcached-backed object cache can keep serving the OLD blog_id for that domain until that specific cache entry expires on its own, because a raw UPDATE statement never fires the WordPress action that would normally clear it.

🔎 The Problem

wp_blogs row updated directly via a migration script:
  blog_id 7, domain changed from old.example.com to new.example.com

Object cache (Redis), group "blog-lookup", key "new.example.com":
  still resolves to blog_id 3 (a different, unrelated site) because that
  key was cached from an earlier request and nothing told the cache the
  mapping table changed underneath it.

✅ Fix: Update Through the API, Then Flush the Cache

  • Make domain-mapping changes through WordPress’s own API (`wp_update_site()` or the Network Admin “Edit Site” screen) rather than editing wp_blogs/wp_site directly in the database, since only the API call fires the actions that clear the relevant object cache keys.
  • If a direct database edit already happened, manually flush the “blog-lookup” cache group (or run a full cache flush if that’s not exposed) instead of assuming the new row will simply be picked up on the next request.
  • After remapping, confirm the fix with `get_blog_id_from_url()` or by visiting the domain in a private window with cache busting, since a browser or CDN-level cache of the previous site’s response can mask whether the server-side fix actually worked.

🚨 Why This Is Dangerous

  • A visitor — or a login form — silently landing on the wrong network site after a domain change can mean a password typed into the wrong site’s login screen, or one client’s content appearing under another brand’s domain, invisible until someone actually clicks through.

The database row can be correct the instant you save it; the cache in front of it decides when that becomes true for visitors.

— WordPress Admin

Related posts:

Wordpress: Fix Permalinks 404ing After Switching PHP Versions

WordPress: Fix Permalinks 404ing After Switching PHP Versions

WordPress: Fix a Custom Login URL Plugin Breaking the Admin-Ajax Nonce Check Because It Still Expect...

WordPress: Fix a Custom Login URL Plugin Breaking the Admin-Ajax Nonce Check Because It Still Expect...

WordPress Sites Age Poorly Without Breaking

WordPress Sites Age Poorly Without Breaking

Views: 1

Post navigation

The AI Prompt That Negotiates a Lower Bill With Your Internet Provider
WordPress: Fix the Block Editor Pasting Hidden Formatting Marks

Leave a Reply Cancel reply

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

November 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« Oct    

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,059)
  • Get the User Name and Domain Name from an Email Address in SQL (983)
  • How to add default value for Entity Framework migrations for DateTime and Bool (981)
  • Get the First and Last Word from a String or Sentence in SQL (861)
  • How to select distinct rows in a datatable in C# (856)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (658)
  • Add Constraint to SQL Table to ensure email contains @ (613)
  • Average of all values in a column that are not zero in SQL (571)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (549)
  • Find numbers with more than two decimal places in SQL (477)

Recent Posts

  • Visual Studio: Fix Quick Actions Hiding Behind a Stale Squiggle
  • Photoshop: Fix a Smart Filter Resetting After You Relink It
  • Ajax: Fix a Cancelled Request Still Updating Stale UI State
  • C#: Fix a Span Captured by a Lambda Throwing at Runtime
  • The AI Prompt That Converts a REST Endpoint Into a Typed SDK
  • Git: Fix a Worktree Locking a Branch Needed Somewhere Else
  • Asp.Net Core: Fix a Background Service Leaking Scoped Dependencies
  • SQL Server: Fix a Columnstore Index Fragmenting After Bulk Deletes
  • Docker: Fix a Container Losing Logs After a Restart Policy
  • Asp.Net Core: Fix Output Caching Serving a Stale Authorized Page

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,059)
  • Get the User Name and Domain Name from an Email Address in SQL (983)
  • How to add default value for Entity Framework migrations for DateTime and Bool (981)
  • Get the First and Last Word from a String or Sentence in SQL (861)
  • How to select distinct rows in a datatable in C# (856)

Recent Posts

  • Visual Studio: Fix Quick Actions Hiding Behind a Stale Squiggle
  • Photoshop: Fix a Smart Filter Resetting After You Relink It
  • Ajax: Fix a Cancelled Request Still Updating Stale UI State
  • C#: Fix a Span Captured by a Lambda Throwing at Runtime
  • The AI Prompt That Converts a REST Endpoint Into a Typed SDK

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com