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


33 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
      Twitter: andrea_r
      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.

    • epsi says:

      I’ve had a little problem with DNS,
      but now it is working on my wpmu.local.

      For troubleshooting you may take a look at
      http://forum.linux.or.id/viewtopic.php?f=12&t=20978

      This forum using Bahasa Indonesia Language,
      but the command line output is self explanatory.

      Hope this help for anyone who experience WPMU+DNS issue.

  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?

  5. Danny G Smith says:

    Our dns is provided by a windows domain. I don’t speak windows. Would you happen to know how to explain what needs to be done on windows?

  6. Just following on from Remkus’s question about having more than domain on a server using wildcards. I’m currently trying to do this on Lighttpd.

    I have one WPMU running like a dream on my Lighttpd VPS. I have used the virtual hosting in Lighttpd to run a separate WPMU with its own domain. The problem is that all domain mapping for this second WPMU is reverting back to the root of the primary WPMU site. Any ideas how to fix this?

  7. Nephilim says:

    Even more questions: :)

    How do I enable wildcard sub-subdomains, like [*.blog.mydomain.com]? Should it work the same way? On my server (or rather, on my web-hosting providers server (Linux/Apache/CPanel)), it doesn’t seem to work… :-/

  8. Nephilim
    It sounds like your using shared hosting. I would suggest that you contact your hosting company and establish if they support the use of wildcard domains on your hosting plan.
    In my own experience I have used hosting packages with the C-Panel interface that will allow you to specify wild card domain for you site but not actually support it.
    In the end I went for a Linux VPS and this allowed me full control of the wild card configuration.
    I hope this helps.

    Jason

    • Nephilim says:

      Hi Jason, and thanks for your reply!

      Yes, I’m on a shared hosting but/and they do support wildcard domains and don’t have too many restrictions overall. I have no problem creating an ordinary [*.mydomain.com] wildcard, but can’t create a wildcard domain at a deeper hierarchy [*.blog.mydomain.com].

      My hosting company doesn’t seem to know why, so I’m trying to find some information myself, so I can point them in the right direction. :)

      This _should_ technically be possible, creating a sub-subdomain wildcard like [*.blog.mydomain.com], should it not?

  9. Nephilim says:

    Good to know it can be done – I haven’t found too much information about deeper domain wildcards…

    If I create a WPMU blog named “whatever” it will get the address [whatever.blog.mydomain.com], but if I don’t manually add the subdomain [whatever.blog.domain.com] and point it to [blog.domain.com], the name will not get resolved.

    I guess this is a server/CPanel setting/issue, but your blog topic seemed close enough, and you seem to be quite knowledgeable. :)

    The only way I have to create a wildcard domain in CPanel is with the Subdomain tool – the DNS tools (simple and advanced) won’t accept [*] as input. The problem is – when I try to add [*.blog.mydomain.com] with the Subdomain tool, CPanel reports [*.blog.mydomain.com] beeing created, but actually [*.mydomain.com] is created instead.

    • andrea
      Twitter: andrea_r
      says:

      It’s because you’re on shared, basically. :) You’re stuck doing it this way:

      “If I create a WPMU blog named “whatever” it will get the address [whatever.blog.mydomain.com], but if I don’t manually add the subdomain [whatever.blog.domain.com] and point it to [blog.domain.com], the name will not get resolved.”

      You may be able to use the multi-site plugin (we sell one, linked at the top) to create another Site called blog.whatever.com, and then create the blogs off that site. But again, it’d be a whole lot easier to do if you were in at least a vps. Then there’s some hardcore settings to fiddle.

      • Nephilim says:

        If you have some seconds to spare – what exactly does “it’s because you’re on shared, basically” mean? ;)

        Is this due to purely technical reasons because of the shared hosting, or do you assume my host just don’t offer this feature?

        A VPS is not an option at the moment – if this can’t be resolved, I’ll probably just register another “dedicated” domain just for the blogs, and use the ordinary [*.domain.com] wildcard possibility.

        • Andrea_R
          Twitter: andrea_r
          says:

          It’s entirely technical reasons with the way most shared hosts set up their servers.

          I’ve dealt with quite a few on behalf of clients, so it’s not an assumption, it’s from actually fighting with support. ;)

          I’ve done the same thing you want with our multisite plugin, where blog.yourdomain.com was another *site* on the system, with sub-blogs under it.

          The client I did this for may have been bumped up from the bottom-level shared account though.

          I’ve seen better hosting accounts be able to do this for as little as $15 or $20 a month.

    • Nephilim says:

      An update – got the wildcard sub-sub-domain working! Kind of.

      Actually, it probably “worked” the whole time. I still can’t create a [*.blog.mydomain.com] domain record, but the [*.mydomain.com] wildcards really _is_ a wildcard :) – the [*] can consist of numerous subdomains and periods.

      I now direct [*.mydomain.com] to [blog.mydomain.com] – and [whatever.blog.mydomain.com] now works.

      The obvious drawback is that any non-existant subdomain name to [mydomain.com] now leads to my blog [blog.mydomain.com] instead of my home page [mydomain.com], but that’s really not a problem. Yet. :)

  10. [...] only sub-domains, yet still use subdirectories within the WP install. At least, that’s what Andrea mentioned in the WP [...]

  11. Hi All,

    Please help me. I have installed WordPress MU in my local machine when i create sub domain it has created but when i run on browser it is giving me error like this “Firefox can’t find the server at sub.localhost.localdomain”
    my main domain is
    http://localhost.localdomain/wpmu
    my sub domain is
    http://sub.localhost.localdomain/wpmu

    Please give me any suggestion i have tried Andrea solution but i thing i have done some mistake that is why it is not working.

    Thanks
    Rajesh Gurjar

    • Jason says:

      Rajesh
      I take it your running WPMU on you own local linux/window box and you don’t have your own DNS server running. this is a total different beast. You could try adding host entries to your host file on your cleint pc with the sub domain names and the ip address of the server.

      To get it working as per a live install like on the web you will need to setup a dns server and have your client machine resolve domain names from it.

      Regards
      Jason

    • andrea
      Twitter: andrea_r
      says:

      If you’re on localhost, you have to create the subdomains manually in your hosts file as wildcard subdomains don’t work that way.

  12. Thanks Json and Andrea,

    Thanks for giving me your precious time for me. The problem is solved in local machine when we give manually sub domain on hosts file. but i want on server so i have not do the same because on server client create lot many sub domain please give me any solution for server.

    Thanks in Advance

    • andrea
      Twitter: andrea_r
      says:

      On the server you have to set up wildcard subdomains.

    • Jason says:

      Rajesh
      There is really only one answer if you want to run it local you will need to setup a local DNS server on your lan that you can configure your wildcard dns on.

      It might be easier to find a hosting company that has a cheap hosting package that supports wildcard dns and do a test install for yourself on the web.

      Do you really want to put yourself through configuring Unix/Linux DNS or WindowsNT Server dns configuration to try it out or do you have a business case.

      We run our own internial DNS servers so adding a few non existant domains with wild card support really was not an issue.

  13. I have WP3.0 Multi-Site (Subdomains) working on a shared hosting account (the $4.95/month kind).

    I set up wildcard DNS from CPanel, simply putting * (asterisk) in the subdomain name, for each domain I want blogs for (mydomain.com, myotherdomain.info, etc).

    I had to install WP3 in public_html for it to work, it wouldn’t work in an add-on domain. (Said another way, WP3 had to be in public_html)

    In this setup, creating a sub-subdomain, e.g. chess.blogs.mydomain.com, makes a folder chess in public_html, not in public_html/blogs. So you’d have to include that in your mapping. I haven’t tried using the Domain Mapping plugin to map to a sub-subdomain such as anything.blogs.mydomain.com; it does work fine for anything.mydomain.com.

    I made a blog post with instructions for all the changes I had to make, to have my existing web sites work and to have WP3.0 work multi-site, at WordPress 3.0 Multi-Site Installation with Existing Web Sites.

  14. paul says:

    Hi!

    I’ve set up my network successfully but I’m wondering how to deal with an issue:
    I want to have subdomain.example.com where example.com is a domain mapped to a virtual blog. Or it can be example.com/subdomain

    basically , I want to use subdomains or subfolders for dev sites to show clients.

    but I don’t want to use the top level domain as it is not my web design domain. So I can’t create a new blog in the multisite the normal way because it will get the subdomain.notmydesigndomain.com URL

    is this possible?

    thanks

    • andrea
      Twitter: andrea_r
      says:

      So you want to map each one to a subdomain of the client’s site? Yeah, you can do that wit the domain mapping plugin.

      Just use a CNAME record instead of an A record.

      • paul says:

        Andrea, thanks for the quick reply.
        Basically, when you create a new blog on multisiite, you fill in a box which then appends .topleveldomain.com to it, so you’ll get blog.topleveldomain.com
        But I want the blog URL to be blog.sideradesign.com, where sideradesign.com is mapped to another blog on the same install : sideradesign.topleveldomain.com

        does that make sense?

        • andrea
          Twitter: andrea_r
          says:

          You still need the domain mapping plugin. :)

          You;d map the other domain, then you’d map that new subdomain to another blog.

          Either way, you still have to set up the other sites first.

          • paul says:

            thanks, it works perfectly.
            the only problem is that I have to ask my hosting provider to add the CNAME every time

  15. marc
    Twitter: marcblackwell
    says:

    Hello, this seems like the right place to ask questions about Multi-sites and subdomains.

    My wife and I are photographers, and we want to have 4 sites under 1 WordPress Roof.

    1.) blackwellphoto.com
    2.) marc.blackwellphoto.com
    3.) stacey.blackwellphoto.com
    4.) weddings.blackwellphoto.com

    I am using Godaddy for my hosting and domains.

    I have a freshly installed version of WP 3.0 on my site. Following the instructions in the Codex, here’s what happens.

    I have logged into Godaddy, and in my Total DNS Control settings I added a new A (Host). For the Host Name, I put: “*”, & the Points to IP Addy field, my IP addy.

    I do not know how to follow this step: “1. Open up the httpd.conf file or the include file containing the VHOST entry for your web account.
    2. Add this line:

    ServerAlias *.example.com”

    I have added the following code: “define(‘WP_ALLOW_MULTISITE’, true);” above the ‘happy blogging’ section on wp-config.php

    I logged into WP, click tools>networks> and check “sub domains”.

    I get this warning after that: Warning! “Wildcard DNS may not be configured correctly!

    The installer attempted to contact a random hostname (76b768.blackwellphoto.com) on your domain.”

    I add the rest of the code to the wp-config file, and can’t find the .htaccess file on my site at all.

    Do I need to add the subdomains (marc, stacey, weddings) on Godaddy first? Is my DNS correct?

    Please help!

    I have set up WordPress MultiSite on blackwellphoto.com. I get all the way up to editing the .htaccess file. Why? Because I don’t have one. If I create one, the entire WP site crashes and I have to reinstall.

    After editing the wp-config.php file with the code, and logging back into WordPress I see the options to set up the network. When I click “Create New Site” it seems to work fine, however I get this code.

Leave a Reply

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-Spam Image