What is Wildcard subdomain

Wildcard subdomain is a wildcard (catch-all) DNS record that will match request for non-existent subdomains. It is specified by a “*” as part of the domain name, example: *.yourdomain.com.

With wildcard subdomain setup, you do not need to create a DNS record for each subdomain. Example: unlimited subdomain for WordPress multisite setup.

In this tutorial, you will learn how to create a wildcard subdomain with RunCloud.

Step 1: Create a wildcard subdomain with domain registrar

In order to create a wildcard subdomain, you need to add a wildcard DNS recoord for your domain name. You will need to access your domain name control panel for DNS management, usually provided by your domain registrar.

Here I will show you how to create a wildcard subdomain for your RunCloud server. In this example, I am using Cloudflare for DNS management.

Goto DNS management page and follow the steps below to create a wildcard subdomain DNS record:

  1. Select “A” for record type (you can also use CNAME)
  2. Use “*” for DNS record name
  3. Fill in your RunCloud server IP address for the DNS record value
  4. If you are using Cloudflare, select “grey cloud” to skip going through Cloudflare network.
  5. Click “Add Record” button to add the wildcard subdomain DNS record

Next, we need to setup the RunCloud server to response to the wildcard subdomain requests.

Step 2: Create web application for wildcard subdomain with RunCloud

There are two ways to response to the wildcard suddomain requests:

  1. create web applications to response to each wildcard subdomain request. Example: a.yoursite.com, b.yoursite.com, c.yoursite.com, …
  2. create a web application that answers all wildcard subdomain requests. Example: *.yooursite.com

Solution 1: Create a web application for each subdomain
At “Web Application” in RunCloud panel… Click “Create Web App” button to create a new web application.

Remember to type your desire subdomain name (a.yoursite.com) for “Domain Name”. select PHP version and web application stack then click “add web application” button to create a new web application on your server.

Any future request to the subdomain will be served by the web application you just created. Do not need to add a new subdomain DNS record at domain management panel.

Any subdomain request that is not assigned to any web application will be fall back to the default web application (if you have setup one).

Solution 2: Create a web application to answer all subdomain requests

If you have a web application like WordPress multisite, that will answer all subdomain requests, then use this approach to setup the web application that for wildcard subdomain.

Similar to Solution 1 above, create a new web application but at the “Domain Name” field, you enter a wildcard subdomain instead, example: *.yoursite.com

The web application with wildcard subdomain will answer all subdomain requests that is not assigned to any other web applications.

Let’s say you have a web application with domain name “client.yoursite.com”, then request for “client.yoursite.com” will not be answered by the web application with wildcard subdomain “*.yoursite.com”.

Tips: After creating a wildcard subdomain, you would like to make a free SSL certificate (HTTPS) for all the subsites.

Summary

In order to create a working wildcard subdomain, you need to setup it at domain registrar (add wildcard DNS record) and RunCloud panel (create web application).

Once setup wildcard subdomain, you do not need to manually add new subdomain DNS record for your new web application or website.

All you need to do is create a new web application using RunCloud panel and it will work automatically.