Howto use subdomain WordPress Multisite 3.x without dashboard site?

So I wanted to log in to write about how to set up WordPress 3.x multisite to work with subdomains but the main site NOT running WordPress. Seriously, if you are okay with running WordPress on your main site (not only on subdomains), this guide is not for you. If you’re that girl, you’d want to check the normal network installation instructions.

WordPress is made to control the “host site”, so having this setup is speciality. I couldn’t find guides on doing this, so I’ve burned incredibly much time on it.

My setup (what I want to do)

  • I have a site; example.com, where I run a django site (or whatever else that’s NOT WordPress).
  • I want to have subdomain WordPress Multisite install, so I want myblog.example.com and yourblog.example.com.
  • I also want to have custom domains where I own it, so instead of using yourblog.example.com, I want to use yourblog.net.

So those three points should be easily doable, at least it sounds like an easy and nice requirement. Well, it was not so easy, but hopefully it’ll be easier with this guide.

Obviously you need to install WordPress, and set it up to be a Multisite-install. I’ll refer the normal steps here, but use the Create A Network instructions on the WordPress codex for a more fleshed out guide.

If you use the Codex-guide or have already set up WordPress Multiuser, add the two lines from my step 5 and start from step 8.

HOWTO

  1. Setup a normal WordPress blog. You know this. Install it normally. I set mine up as wp.example.com, this will be my dashboard site (so, NOT example.com like the normal Multisite setup). Update it, if there’s updates for it (I had one, probably because I set nn_NO as language in WPLANG).

  2. When done, open up wp-config.php and add the following line just before “That’s all …”

    define('WP_ALLOW_MULTISITE', true);
    
  3. Go to Admin -> Tools -> Network. Choose subdomain, it will say like site1.wp.example.com and site2.wp.example.com, we’ll just have to fix that later.

  4. Ignore Wildcard DNS error. Make blogs.dir:

    mkdir wp-content/blogs.dir
    sudo chown www-data wp-content/blogs.dir
    
  5. Replace the WP_ALLOW_MULTISITE in your wp-config.php with the following (the last two lines are different from a normal multisite install):

    define( 'MULTISITE', true );
    define( 'SUBDOMAIN_INSTALL', true );
    $base = '/';
    define( 'DOMAIN_CURRENT_SITE', 'wp.example.com' );
    define( 'PATH_CURRENT_SITE', '/' );
    define( 'SITE_ID_CURRENT_SITE', 1 );
    define( 'BLOG_ID_CURRENT_SITE', 1 );
    
    define( 'NOBLOGREDIRECT', 'http://example.com' );
    $cookie_domain = '.example.com';
    

    PS In my current install, I did something very wrong, I didn’t make the dashboard site first, and so I had to change BLOG_ID_CURRENT_SITE to 9.

  6. If you use apache, add this to your .htaccess-file:

    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    
    # uploaded files
    RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L]
    
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule . index.php [L]
    

    However, if you’re like me, and use nginx, I use this rule to enable WordPress Multisite:

    location / {
        index  index.html index.htm index.php;
        rewrite ^.*/files/(.*)$ /wp-includes/ms-files.php?file=$1 last;
        if (!-e $request_filename) {
            rewrite ^.+/?(/wp-.*) $1 last;
            rewrite ^.+/?(/.*\.php)$ $1 last;
            rewrite ^(.+)$ /index.php?q=$1 last;
        }
    }
    
    location ~* ^.+\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|ogv|ogg)$
    {
        rewrite ^.*/files/(.*(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|ogv|ogg))$ /wp-includes/ms-files.php?file=$1 last;
        expires 30d;
        break;
    }
    
  7. Press the “login again” button on the install (or just login again :P).

  8. Install my plugin, Remove Domain Part (Direct download). All it does is to remove .wp. from the domains so that site1.wp.example.com becomes site1.example.com on blog installation (when you choose “New site”).

    1. If you use something else than .wp., you need to change it in the REMOVE_DOMAIN_PART definition in the plugin.

    2. Network Activate the plugin (if you don’t use fontend signups, you may choose to only activate it on the main site).

  9. Install WordPress MU Domain Mapping, follow the install instructions. Short version:

    1. Link sunrise.php (or merge if you’ve got it from before) to the wp-content folder. > ln -s plugins/wordpress-mu-domain-mapping/sunrise.php wp-content/
    2. Add define( 'SUNRISE', 'on' ); to wp-config.php.
    3. Network Activate it…
  10. And now for the small hack that will make domain mapping work again with our setup. Open up your wp-content/sunrise.php, and add this elseif to the last if-block (all the way at the bottom):

    elseif ( isset($cookie_domain) )
        define( 'COOKIE_DOMAIN', $cookie_domain );
    

    Many people error out here, check a example paste of their new sunrise.php someone in the comments did.

  11. Log in, go into Network Admin and set up Domain Mapping. The domains themselves you can map from the site admin pages, under Tools.


And now everything should work.

55 thoughts on “Howto use subdomain WordPress Multisite 3.x without dashboard site?”

  1. Hei Odin

    Great post!. Your setup is quite like mine. I am interested in having subdomains, and having custom domains pointing to some of them. (Wheter the main site is WP or static pages doesn’t matter to me)

    In step 4, you say “Ignore Wildcard DNS error”. Does that mean that this will work, even if the server is not configured to accept DNS wildcards?

  2. Kjetil: Thanks!

    Yes, it will work without DNS wildcard. I will put in a wildcard later, but right now I do this to add a new domain:

    1. Add a DNS CNAME mypage.example.com to the server
    2. Register «mypage.wp.example.com» in WordPress (autofixed to mypage.example.com)
    3. (optional) DNS CNAME on mypage.com, and add that in Custom Domain
  3. i followed the tutorials, downloaded the plugin, replaced “.wp.” in the script to “mysubdomain” and “example.com” to my “domain.com”

    everything seems to work fine, except when i try to create a new site, i get this error: Warning: Missing argument 2 for remove_domain_part() in /home8/donmedpo/public_html/multisite/wpm/wp-content/plugins/removedomainpart.php on line 17

    Warning: Missing argument 3 for remove_domain_part() in /home8/donmedpo/public_html/multisite/wpm/wp-content/plugins/removedomainpart.php on line 17

    Warning: Missing argument 4 for remove_domain_part() in /home8/donmedpo/public_html/multisite/wpm/wp-content/plugins/removedomainpart.php on line 17

    Warning: Missing argument 5 for remove_domain_part() in /home8/donmedpo/public_html/multisite/wpm/wp-content/plugins/removedomainpart.php on line 17

    Warning: Missing argument 6 for remove_domain_part() in /home8/donmedpo/public_html/multisite/wpm/wp-content/plugins/removedomainpart.php on line 17

    Warning: Cannot modify header information – headers already sent by (output started at /home8/donmedpo/public_html/multisite/wpm/wp-content/plugins/removedomainpart.php:17) in /home8/donmedpo/public_html/multisite/wpm/wp-includes/pluggable.php on line 897

  4. Pierre: Hey!

    You’re not supposed to change anything in the plugin. REMOVE_DOMAIN_PART is supposed to be .wp. if your “main site” is named wp.domain.com.

    If you actually installed your first site to mysubdomain.domain.com then you could change .wp. to .mysubdomain., but that is only if that is your “main site”.

    Did you catch that? It’s a bit mind-bending :-)


    But the rest of the errors seem like your version of WordPress expects something else being sent from wpmu-function. Can you tell me the WordPress-version you are running? I’ll try to look into it.

  5. Pierre: OK, I made a version 1.1, I think I’ve fixed the problem! :D

    I found out that you have to tell WP how many arguments you need. And, well, I only really use one of the arguments, so I just changed to that.

  6. Pierre: It’s there allright, your browser has just cached it for 30 days. You need to press CTRL+F5 or something like it.

    Anyway, I’ll send it to your email as well.

  7. Odin, allow me to bug u some more… plugin works great, but it seems its conditional.

    when superadmin creates a site in the dashboard, the x.wp.domain.com becomes x.domain.com just as the plugin is supposed to make it.

    it gets bad when a user signs up for a site at the front end (/wp-signup.php). the plugin does not strip the “.wp.” part of the url. typing “x.domain.com” redirects you to “domain.com”

    any work around for that?

  8. Pierre: Hey. I never use that feature, but I tried it now.

    However, I didn’t find what you were saying to hold when I tested it; this happened;

    New site signup (for user): write new site (your x), click enter. “Hooray, you’re new site is ok”, and it gives me the wrong addresses x.wp.domain.com, but that is impossible for me to fix through the API for WordPress. So I can’t fix that with a plugin, have to change core to do that.

    Anyway, that’s a similar fault as the other one. Unfixable. But when I actually go to x.domain.com, everything works as it should.

    Have I misunderstood the problem? Are things different at your place? Maybe I can test directly at your site if the registrations are open?

  9. perhaps you can try it urself and see… signup link: http://multisite.donmedpost.com/wp-signup.php

    after signup, x.donmedpost.com doesnt work but x.multisite.donmedpost.com works. (where x is the subdomain domain u choose)

    I will like to state that the plugin works super without any glitch as far as i can tell when the subdomain is created from the superadmin panel.

    One more thing in the superadmin dashbord, under sites, it is possible to edit the site info of sites created through the front end and strip the “.multisite.” part of the url (“.wp.” in your tutorial). perhaps there could be a script to automate that job…?? just hoping it will be a piece of cake for someone with your extensive knowledge.. ;)

  10. Pierre: OK. Remove Domain Part 1.2 now rewrites emails to take away the “.wp.” (or in your case “.multisite.”).

    It should also properly activate the blogs registered from the frontend.

    HOWEVER; a new requirement for such frontend signups; you must Network Activate the plugin for that to work.

  11. Done that and it works! great work.

    one teeny tiny problem. when someone sign up for a site, after the the whole process, the person is given a link. the link has x.wp.domain.com. the link will not work. because of the “.wp.” part in the link. Surely when the the person types x.domain.com, the blog appears. but wordpress still provides the automated “x.wp.domain.com” is there anyway to edit that? and secondly on sign up page, wordpress writes beside the subdomain box “.wp.domain.com” – it misleads the person to think the url of the blog will be “x.wp.domain.com” a Remove Domain Part 1.3 will be lovely. :)

  12. Pierre: The parts of the signup:

    1. Signup, it says you will get an adress + wp.domain.com (BUG)
    2. Signup, when finished a page says “you have to activate”, on this page the link to your site is x.wp.domain.com (BUG)
    3. Activation email, the first link goes to wp.domain.com/activate (CORRECT) the second link go to x.domain.com (CORRECT)
    4. When activated, the two links to your site and login are x.domain.com (CORRECT)
    5. You get an email saying the site is set up, and it has x.domain.com as URLs (CORRECT)

    I tested it on your installation, and it works the same there. Am I correct, you are talking about the bugs 1. and 2., the rest is working right?

    I’ll look at that later, need to do some other stuff now :-)

  13. all true…

    the rest are all working. one more bug. after activation, it gives you a page ” Your account is now active! Your site at x.wp.donmedpost.com is active. You may now log in to your site using your chosen username of “x” ….. “

    that link is a bug too.

    In general your plugin is SUPER. good work man. when u get time, u can take a look at the minor bugs. thanks a lot for your help. If you got any new plugins, feel free to drop the link in my inbox so i can try it out. will check ur blog regularly too… :-)

  14. Hi Odin.

    Thanks a lot for your post, that’s a lot of help indeed and saved me a huge amount of time.

    I’m left with only one problem… when I try to access “test.mysite.com/wp-admin” I get a 404 error.

    “test.mysite.com” works perfectly, but I can’t get to the dashboard of the site.

    Here is my .htaccess:

    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    
    uploaded files
    
    RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L]
    
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule . index.php [L]

    Thanks again for your help!

  15. Hmm. I wonder how many that actually read this tutorial/howto, since it’s only the ones who have problems who post here as a comment. Would be nice if it is actually helping many :-)

    Cassio: Hey :-) Can you either send me the address by email (odin.omdal at google’s email service), or put it here?

    Maybe your server isn’t set up correctly? test.mysite.com/wp-admin/index.php <= does that work?

  16. Benjamin: As always, it’s really hard to say without looking at the real site and seeing what it does.

    You’re saying that the normal site works (subdomain.example.com), but not the admin panel there (subdomain.example.com/wp-admin/)?

    Or do you mean that the dashboard SITE doesn’t work, that is wp.example.com?

    It’d be easier to look at the site itself. And www.subdomain.example.com is something you’d have to put in extra code to handle. You need to redirect it to subdomain.example.com from nginx or apache. Or you need to do major trickery to get the www to work.

    If I were you, I’d skip the www, it’s just irritating anyway (obviously you should always redirect them to the real domain).

  17. Upgrading WP Domain Mapping will now kill the sunrise. Or maybe not for everyone, but I’ve actually symlinked my sunrise.php to the plugin’s.

    Maybe I should try to get some way to specify cookie_domain upstreamed…

  18. When I attempt to access my mapped url, it goes to the main domain of the whole site. It doesn’t even go to my primary subdomain. I need to map it to sub.sub.primary.com. Is there any reason why this would be happening? I have followed these instructions exactly.

  19. dv8or: OK. So it’s easier to clear up what is happening:

    You have mysite.com going to mysite.primary.com, your dashboard site is sub.primary.com.

    That will make WordPress do mysite.sub.primary.com when you add it. The plugin is set up with “.sub.” as the REMOVE_DOMAIN_PART setting, and it is running and network-activated.

    So:

    when you go to mysite.com/wp-admin/, you are redirected, that is how it is supposed to be. But you say you are getting redirected to primary.com/wp-admin/ (which is **NOT** a WordPress site, right?), instead of mysite.primary.com/wp-admin/ as you expect? Or mysite.sub.primary.com/wp-admin/ if you are not running the remove_ domain part plugin. Is that correct?


    Any public instance to look at?

  20. Hi Odin,

    Just a comment to thank you, you saved my day and maybe more :) I was stucked with an impossible subdomain login and I realise by reading your post that you setted the $cookie_domain value up to a wider range than it was on mine by removing the www.

    Continue posting, guy’s like you make the net works !

    Vince

  21. I am not sure how to understand “add this elseif to the last if-block”.

    Is this code correct?

    dmtable = $wpdb->base_prefix . ‘domain_mapping'; $dm_domain = $wpdb->escape( $_SERVER[ 'HTTP_HOST' ] );

    if( ( $nowww = preg_replace( ‘|^www.|’, ”, $dm_domain ) ) != $dm_domain ) $where = $wpdb->prepare( ‘domain IN (%s,%s)’, $dm_domain, $nowww ); else $where = $wpdb->prepare( ‘domain = %s’, $dm_domain );

    $wpdb->suppress_errors(); $domain_mapping_id = $wpdb->get_var( “SELECT blog_id FROM {$wpdb->dmtable} WHERE {$where} ORDER BY CHAR_LENGTH(domain) DESC LIMIT 1″ ); $wpdb->suppress_errors( false ); if( $domain_mapping_id ) { $current_blog = $wpdb->get_row(“SELECT * FROM {$wpdb->blogs} WHERE blog_id = ‘$domain_mapping_id’ LIMIT 1″); $current_blog->domain = $_SERVER[ 'HTTP_HOST' ]; $current_blog->path = ‘/'; $blog_id = $domain_mapping_id; $site_id = $current_blog->site_id;

    define( 'COOKIE_DOMAIN', $_SERVER[ 'HTTP_HOST' ] );
    
    $current_site = $wpdb-&gt;get_row( "SELECT * from {$wpdb-&gt;site} WHERE id = '{$current_blog-&gt;site_id}' LIMIT 0,1" );
    $current_site-&gt;blog_id = $wpdb-&gt;get_var( "SELECT blog_id FROM {$wpdb-&gt;blogs} WHERE domain='{$current_site-&gt;domain}' AND path='{$current_site-&gt;path}'" );
    if( function_exists( 'get_current_site_name' ) )
        $current_site = get_current_site_name( $current_site );
    
    define( 'DOMAIN_MAPPING', 1 );
    

    } elseif ( isset($cookie_domain) ) define( ‘COOKIE_DOMAIN’, $cookie_domain );

    ?>

  22. Hello

    I saw one of your post about subdomains in WordPress. I thought you might help me in my problem.

    There is place on a page with general contact data (email, mobile).

    I’d like to prepare this part depending on a user under different subdomain, i.e. http://www.formore.pl displays general contact data http://www.user1.formore.pl displays contact data of user1 http://www.user2.formore.pl displays contact data of user2

    Do you have any idea what’s the best way to do it? Thanks in advance for any help

    Tomasz

  23. Hmm. Tere’s many ways to do it. Not directly relevant to what I’ve been doing though. Depends on how you want to do it. Is it 10.000 users? Is it only 30? Will they own the sites? Shall they be able to fix it/change it?

    There are so many variables, I don’t know what you’ll use it for, and it depends what is the best way.

    So, one way: make a WP template that has all the text and then just inject the variables from the blog. Every single blog has a name and a tagline and the admin of that blog (which owns it) etc, you could insert some more variables like that.

    Another way; when you create a new wordpress site, — you can have a small plugin that creates this page for you for the user. So that it is fixed when they start their site, and then they may change all that information and make it fit afterwards.

    I’d recommend you to do a quick search on the wordpress plugin site, and search for “clone multisite” or “add page plugin” and other search terms.

    And if you can’t find it in 15-20 minutes, I’d rather just write a new plugin to do it. I’ve wasted too much time looking for ready solutions when it’d be quicker to just do it myself

  24. Thanks for your answer.

    I red a bit and it seems I need to use wordpress multisite to manage subdomains anyway.

    Sorry with the mess on your personal blog ;)

  25. Oh, you don’t even want MS. If so, you can make a template (my_about.php) and do something like:

    switch ($_SERVER['HTTP_HOST']) {
        case "user1.formoe.pl":
            $name = "User One";
            $email = "user1@example.com";
            break;
        default:
            $name = "Headquarters";
            $email = "hq@example.com";
            break;
    }

    echo "E-mail: $email"

    Then you don’t need to use multisite. Of course, every single web site on the different domains will look the same except for that single page, plus you need to override the automatic redirect that WP does.

    So yeah, I think you should rather go with a real MS setup if you want multiple sites.

  26. I followed the instructions to set things up. The domain name part is being stripped off. However, I cannot log in to the new sites. The log in page accepts the username and password, but will not actually log in. If I enter an invalid password, the error message says that I must have cookies enabled (but they are).

    Any idea what might be wrong with this?

  27. Tomasz: That’s great! Now I know more too without searching for it. ;]

    Tom: It really sounds like the same problems others have had. Are you sure your $cookie_domain is set up correctly, and that you did the sunrise.php changes? :-)

  28. While using miniMU you’d need an additional trick. htacces file should include:

    RewriteCond %{HTTP_HOST} !^www. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

    what adds “www” prefix to main domain and subdomains when someone uses url without the prefix.

    I use the main domain /wp-admin as login page. Assigning the new post to the right post-category will display the post in the right blog than. It’s only mini Multi User plugin, not the full multisite.

  29. It looks like I made a mistake in the edit to sunrise.php. I put the elseif in the wrong place, and noticed after I compared to Anonymous 3 Jun 12

  30. Tom: In other words, I should really make that part easier… Hmm, no good ideas right now.

    update: OK, I added a note, and also said you should add it at the bottom of the file, which is the likely place for it (unless you’ve got an unstandard sunrise-file).

  31. Hi Odin,

    In my case, my main site is iweb.pro-league.vn, when I create new site, it’s site1.pro-league.vn, it works, but when I login from site1.pro-league.vn (site1.pro-league.vn/wp-login.php), I can’t login to admin site, in the address bar it said “site1.pro-league.vn/wp-login.php?redirect_to=http%3A%2F%2Fsite1.pro-league.vn%2Fwp-admin%2F&reauth=1″. So how can I fix it. Please help me.

    By the way, thanks for your good plugin.

  32. Quang: Step number ten is not correctly done, because the cookie your WP is making is wrong:

      wordpress_test_cookie = WP+Cookie+check;
                              path=/;
                              domain=.iweb.pro-league.vn
    

    It should be domain=.pro-league.vn, not the iweb thingy.

  33. Hi Odin, thanks for your reply soon. It was my mistake, I disables line “$cookie_domain = ‘.pro-league.vn';”. But now I enable it but It still doesn’t work. This is in my wp-config.php:

    define(‘MULTISITE’, true); define(‘SUBDOMAIN_INSTALL’, true); $base = ‘/'; define(‘DOMAIN_CURRENT_SITE’, ‘iweb.pro-league.vn’); define(‘PATH_CURRENT_SITE’, ‘/’); define(‘SITE_ID_CURRENT_SITE’, 1); define(‘BLOG_ID_CURRENT_SITE’, 1); define( ‘NOBLOGREDIRECT’, ‘http://pro-league.vn’ ); $cookie_domain = ‘.pro-league.vn';

    define( ‘SUNRISE’, ‘on’ );

    By the way, in step 11, I don’t know how to set up Domain Mapping, I go to Network Admin\Setting\Domain Mapping and I don’t know what I should do.

  34. Hi Odin, this morning, I reinstalled and follow step by step your instruction carefully, and it works.

    Thanks for your awesome plugin.

  35. Quang: Great! It was probably the step 10, because I checked after you did the change and it was still returning the wrong cookie domain.

    That’s where most people fall. It’d be nice to find a way to make that easier/remove that step… Possibly I can try to change the code in Domain mapping.

  36. Hello, Thank you for your plugin and post,it work for me. only found out Yoast’s WordPress SEO plugin XML Sitemap got error with multi site,now I find out it’s caused by sunrise.php,and solved the problem.

  37. Hi Odin,

    I followed your tutorial step by step to test a Multilingual Network within a fresh 3.5 WP-Multisite-Install on my localhost and everything works like a charm. Deeply grateful, for I would have been completely lost without your plugin and your helpful instructions here. Thanks for sharing!

    Heike

  38. Hi Odin, i have this 123nagar.com . Now i want sub1.123nagar.com and sub2.123nagar.com . I have installed WP in 123nagar.com with multi site network. I installed WP in sub1 and sub2 folders also with multi site option. In the main site network dashboard, using Add site option, i added sub1.123nagar.com and sub2.123nagar.com . but i those sites are not getting displayed in network dashboard-> My sites tab. Here only Network admin and 123nagar.com are getting displayed. In A Network setup tutorial from the WP.org post, i can see that, the added site names are getting displayed in network dashboard-> My sites.

    1. Now, i just want to add these 2 sub domains to the network?
    2. If i post in sub1.123nagar.com, how to display those posts in my 123nagar.com home page.?
  39. Heike: Absolutely! But I have not had any time to set up this again. But I will try something simpler then. However, I do forsee a few problems, but maybe there’s better ways nowadays! :)

    Pardhu: No, you should only have one wordpress install. It seems to me that you’ve made several. I can’t really help people too much with this anymore, it is taking me too much time :)

    I want to try finding an easier/better solution. WordPress has changed a lot these last few years and I think as Heike says, there might be better ways to do this nowadays.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.