(dv):Configure a wildcard subdomain

  • This page was last modified on January 30, 2012, at 18:39.
The (mt) Community Wiki is a collaborative project. Any (mt) Media Temple customer or employee may contribute. Not all articles and/or content have been tested for accuracy by (mt) Media Temple.

For officially moderated and tested articles, be sure to visit our KnowledgeBase.

From (mt) Community Wiki

If you wish for all your non-existent subdomains to act as a sort of catch-all, you can do the following to get set up. Mind you, this information is based off of the Parallels Knowledge Base as this is a Plesk operation. Refer to this article for further details: How do I create a wildcard subdomain?.

The first thing you do is create a subdomain for the domain you want. Something like "zz-wildcard" so that it'll appear at the bottom of the list of subdomains. It is important that it be the last one you have listed alphabetically. To do this in Plesk, simply do the following:

  1. Click the Domains link in the left side menu bar.
  2. The domain name itself (example.com).
  3. Click the Subdomains button.
  4. Click Add New Subdomain.
  5. Fill in the information and click Ok.

Once you've done that, you will need to find (or create) your domain's vhost.conf file. You can use the File Manager for the domain or through Virtuozzo (if you are logged in as the root user). It'll be located here: /var/www/vhosts/yourdomain.com/subdomains/zz-wildcard/conf/vhost.conf and the change you'll add is this:

ServerAlias *.yourdomain.com

  • Important note: PLEASE make a backup of your vhost.conf file, just in case something goes wrong.

Once you have made the change, you will need to restart your webservice. You can do it through Plesk or in SSH using this command:

/usr/local/psa/admin/sbin/websrvmng -a -v

After that, any non-existent subdomain should re-route back to the domain itself.

It is important to note that this configuration only sets up the wildcard subdomain. So if a request is made for thisdoesnotexist.example.com the content will be served directly from /var/www/vhosts/example.com/subdomains/zz-wildcard/httpdocs -- If you want this configured to serve content you already have on your server (normally already on a specific subdomain or the parent domain), you'll want to create an htaccess redirect in your zz-wildcard/httpdocs folder pointing to the correct location.