Jun 23, 2014 | laravel, forge, subdomains

Laravel Forge - Wildcard Subdomains


This is a series of posts on Laravel Forge.

Warning: This post is over a year old. I don't always update old posts with new information, so some of this information may be out of date.

If you've ever used a site like Harvest or Slack, you've experienced group-specific subdomains. If your company is named Tighten, you'll get tighten.slack.com, tighten.harvestapp.com, etc.

In order to implement a feature like this on your own Forge-hosted site, you'll need to be able to create a Site that accepts not just one domain but many. Thankfully, this is easy with Wildcard Subdomains.

Allow Wildcard Sub-Domains

When you add a new site, notice that there's a checkbox at the bottom of the form that says "Allow Wildcard Sub-Domains." If you check this box, any subdomain under the domain you enter in the "Root Domain" will be passed to this Site.

Forge Add Wildcard Subdomain Checkbox

How does this work?

Well, imagine you're setting yourself up a Harvest competitor named Schmarvest. You want to set up Schmarvestapp.com so that every subdomain underneath it is reserved for a different user, but you want all of those thousands of subdomains to all be served from one single Laravel app.


If you just create a new site in Forge for Schmarvestapp.com, and don't use the Wildcard Sub-domains checkbox, you'll see your primary domain (schmarvestapp.com) will work just fine. But if you try to visit one of your subdomains, nothing will happen. tighten.schmarvestapp.com won't go anywhere. You could, if you wanted, add a new Site for each of those subdomains, but they'd each be hosted on a completely separate codebase.

Instead, add a Site for schmarvestapp.com that has the "Allow Wildcard Sub-Domains" option checked. Now if you visit any subdomain under your domain (and if your DNS is pointed to Forge correctly), you'll still always hit your one install.

DNS for wildcard

So, all of this has been assuming you have your domain routing set correctly at your DNS. But what is the appropriate routing?

The most appropriate option is a wildcard A record. So, in your DNS provider's editor, add a new "A" record for your domain.

Set the "Name" field to be * (or *.yourdomain.com, depending on the prompts your registrar gives you for format). Set the "Address" field to that of your Forge Server's IP address. And do whatever you'd like with your TTL.

Schmarvest A Record

That's it! Wait for an hour or so and now all requests to this domain and its subdomains will head over to your Forge server.


That's it! Time for Schmarvest world domaination.

Comments? I'm @stauffermatt on Twitter

Tags: laravel  •  forge  •  subdomains

This is part of a series of posts on Laravel Forge:

  1. May 16, 2014 | forge, laravel, papertrail
  2. May 23, 2014 | laravel, forge, queue, beanstalkd
  3. Jun 2, 2014 | laravel, forge, cron
  4. Jun 2, 2014 | forge, laravel, ssl
  5. Jun 17, 2014 | forge, htpasswd, nginx
  6. Jun 23, 2014 | laravel, forge, subdomains
  7. Jul 9, 2014 | forge, laravel, recipes
  8. Jul 25, 2014 | laravel, forge, aws, hosting
  9. Sep 17, 2014 | laravel, forge
  10. Dec 24, 2014 | forge, sculpin, fiveMinuteGeekShow


For quick links to fresh content, and for more thoughts that don't make it to the blog.