Tag Archives: Plugin

New release 1.2 of remove_domain_part plugin for WordPress

When I put the plugin and howto guide out for how to make WordPress multisite work without WordPress monopolizing your main domain, I thought it’d maybe help one or two people a year. However, in this short amount of time I’ve gotten quite a few people looking at it.

So I’ve been fixing bugs and problems they’ve come up with. I just released version 1.2 of my remove_domain_part plugin which is a part of the full setup in the guide.

The changes from 1.0:

  • Frontend signup is now supported.
  • Works on more picky PHP installations.
  • Rewrites activation emails, removing any instances of REMOVE_DOMAIN_PART that it can find.

A better place

If people really start to use it, I should probably put it up on the WordPress plugin directory so that people can get updates and have a better place of finding the plugin.

I thought this use case was extremely small, and hence I didn’t want to invest any time in putting it correctly up. However, it might be beneficial now that I’m not the sole user of the plugin any more.

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.