How do I set up wildcard *DOMAIN* on my droplet?

I’m working on a webapp where users can connect their profile to their domains, but how do I enable wildcard dns in digitalocean? Using vhosts or from the domain panel? Eg: If the user profile is It will be shown on once the user connects the domain.

I’m using

  1. PHP
  2. Apache
  3. Ubuntu
  4. MySQL

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Andy Hattemer
DigitalOcean Employee
DigitalOcean Employee badge
February 16, 2020
Accepted Answer

@Cybil Here is the approach I would take:

Update DNS to direct all subdomain requests to your Droplet

  1. Add your domain without any subdomains to the DO Control Panel. add root domain
  2. Add an A Record entry to DNS where an asterisk * is the host name and your droplet is selected as the target so that all subdomains route Add * wildcard A-Record

Now the DNS record is directing all subdomain URL requests (, to your Droplet. To ensure the root domain is also pointing to, add an @ A-Record too.

Note: From our documentation:

(Use) A wildcard (*). To direct requests for a non-existent subdomain to a server or load balancer, enter *. However, if any kind of DNS record exists for a hostname, the wildcard will not apply; you will need to explicitly create an A record for it.

Update Apache config on Droplet to map all subdomains to the right webapp route

  1. Enable the mod_vhost_alias extension on Apache with sudo a2enmod vhost_alias and then restart Apache with systemctl restart apache2
  2. Update your Apache config to add a VirtualHost block that maps subdomains to the proper PHP route
<VirtualHost *:80>
    DocumentRoot /path/to/webapp

<VirtualHost *:80>
    ServerAlias *
    VirtualDocumentRoot /path/to/webapp/users/%1.php

Lastly restart apache again with systemctl restart apache2


Maybe you want to say Your question is to add subdomains for every user and enable https access?

Maybe you can turn to and it will redirect to a GitHub repo with more information on setting up https. At there you can find what you want.

As for wildcard subdomains, just add * in your DNS console. That means, * is the record, and YOUR SERVER IP is the value.

Regards, Shiroka

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel