Enabling wildcard subdomains

When you install WPMU by default the subdomain option is checked. This is for blogs in the format of username.yourdomain.com.

There are two steps that need to be done to your server in order for this to work.

In Apache, there needs to be a line in the domain’s virtual hosts section as follows:


ServerName yourdomain.com
ServerAlias yourdomain.com *.yourdomain.com
DocumentRoot /your/doc/root/
ServerAdmin webmaster@yourdomain.com

The Server Alias line with the *.yourdomain.com is what controls this. If you do not have access to change this, ask your webhost for support. More and more hosts are enabling this by default.

The second thing that needs to be done is adding the DNS record. Where you add it depends on your domain hosting. Basically, you need to add a line like this:

*. in A YOURIPADDRESS

These wildcards mean that any subdomain request will fall through to the WPMU install, where MU will look up the name in the database. If it finds it, it serves up the blog.

Note: if you choose the subfolder option on installation, you do not have to do either one of these steps.

[Post to Twitter] Tweet This Post 


bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark
tabs-top  banner ad


7 Responses to “Enabling wildcard subdomains”

  1. Sean says:

    *.yourdomain.com or *.yourdomain.com. or just *?

    At least in BIND, I think that *.yourdomain.com from within the yourdomain.com zonefile will be parsed as *.yourdomain.com.yourdomain.com

    The trailing . will tell BIND that it’s not to add the subdomain, and * simply sets a wildcard for the current domain.

    Sean

  2. James D Kirk says:

    And if you’re running an Nginx server, you’d use:

    server {
    listen 80;
    server_name domain.com *.domain.com;
    }

    Note there are only spaces between the domain name listings.

  3. Rahul Bansal says:

    Hi Andrea,

    Thanks for nice article.

    Do you know how to install WPMU in subdomain mode on localhost.

    Wildcards don’t work in /etc/hosts file and nameserver is external to my machine.

    Can I somehow make this work without installing BIND on my local machine?

    Or if I can’t skip BIND, is there a good resource which explains BIND in WPMU context only.

    Thanks,
    -Rahul

    • andrea says:

      If it’s your local windows box, you’ll have to put in each subdomain manually.

      If you want to read up on BIND, the only MU-specific part is “wildcard subdomains”. They are used by other applications, not just MU. Process for setting up is exactly the same.

      • Rahul Bansal says:

        Thanks Andrea.
        I guess installing BIND locally will be better.
        For this MU project I am working on, blogs are created automatically with names decided by third party app.

  4. Remkus says:

    What about if you want to enable more than one domain on a server using wildcards? Do you need to enter each and every domain.tld in the Apache Virtual host section?

Leave a Reply