First-Level Subdomains For All Sites in a WordPress Network

When you create a WordPress network (multisite) in subdomain mode, WordPress recommends that you remove www from the site URL, so the network (site #1) is served from the zone apex, and other sites are served from first-level subdomains. For example:


This is problematic if you need to use CNAMEs for your site (since you can’t CNAME a zone apex) or are migrating a site at and don’t want to use redirects. If you ignore the recommendation, you’ll end up with second-level subdomains:


With some tinkering, it’s possible to have all sites use first-level subdomains, e.g.


Step 1: after creating the network with as the URL, edit wp-config.php:

// Old: define( 'DOMAIN_CURRENT_SITE', '' );
define( 'DOMAIN_CURRENT_SITE', '' );
// Add this line so login cookies are accessible to all subdomains
define( 'COOKIE_DOMAIN', '' );

Step 2: take a database backup
Step 3: run the following queries on your WordPress DB (tested with 3.6.1 and 3.7-beta1):

UPDATE `wp_blogs` SET `domain` = '' WHERE `blog_id` = '1' AND `site_id` = '1';
UPDATE `wp_site` SET `domain` = '' WHERE `id` = '1';
UPDATE `wp_sitemeta` SET `meta_value` = '' WHERE `site_id` = '1' AND `meta_key` = 'siteurl';
UPDATE `wp_options` SET `option_value` = '' WHERE `option_name` = 'home';
UPDATE `wp_options` SET `option_value` = '' WHERE `option_name` = 'siteurl';

Step 4 (optional): point the zone apex of to (wwwizer), which will redirect visitors from to

Note: WordPress treats the www subdomain as a special case. If you use a different subdomain for the network, you’ll need to change each site after creating it:

  1. My Sites > Network Admin > Sites > Edit
  2. Remove second-level subdomain
  3. Leave “Update siteurl and home as well.” checked
  4. Save Changes

Leave a Reply

Your email address will not be published.