Enhance your Matomo On-Premise setup by enabling the use of different domains from a single server installation. Using the same Matomo installation with different domains can help project a more professional image when your sites are unrelated and avoid linking unrelated brands.

For example, if you manage a virtual private server hosting a business services website and also a movie fan site, it might look odd if your analytics domain for the company were related to movies or if your business URL were showing up on the fan site. Depending on your specific configuration it may provide first-party benefits.

If you host your Matomo installation on a typical Linux server with Apache, your website file paths might look something like the following, where example.com and example.org are your two domains:

  • Matomo installation in /var/www/html/matomo
  • example.com in /var/www/html/example.com
  • example.org in /var/www/html/example.org

This guide presents several methods that will allow you to serve the same Matomo installation and tracker via multiple domains.

How to set an alternate Matomo URL with an Apache alias

The first method to enable serving the same installation through two URLs on the same server is by creating an Apache Alias. You can do this by accessing your server’s filesystem and editing the apache configuration file which is usually found at the following path:

/etc/apache2/mods-available/alias.conf

Using your favourite text editor, add the following line to your code, making sure that you update the path to the correct location for your Matomo installation.

Alias "/stats" "/var/www/html/matomo"

Once you have saved the configuration file, restart the Apache service to ensure that it recognises your updated configuration. The example above will then serve all Matomo files through /stats/ on every site on your server e.g. example.com/stats/ and example.org/stats/.

Note: It is important that you add this code to your primary apache configuration and not in a virtual host file. As this configuration will add an alias for all domains, so you might want to limit the aliasing by folder if this is not appropriate.

If your host doesn’t allow you to edit your Apache configuration or your host doesn’t have one, you may be able to use a symlink instead. This involves creating files in the relevant folders that automatically redirect the user to the correct server location. With this method, you will need to create a symlink for each domain that you would like to configure.

To get started, log in to your server via your SSH credentials. Once there, enter the following command, making sure to update the first path for the domain folder that you would like to redirect and the second path to the location of Matomo on your server.

ln -s /var/www/html/example.com/stats /var/www/html/matomo

Repeat this process for each of the domains that you would like to be be able to access Matomo through using the /stats/ URL path.

Note: Since many content management systems remove files and folders during an update, it is possible this symlink file will get deleted over time. If this does happen, another method may be more appropriate, or you can re-run the above command to get things set up again.

More advanced users may want to consider using the Matomo Tracker Proxy script. The proxy tool uses symlinks to set up multiple domains on a single Matomo installation without revealing the original server URL. You can download the proxy files and find full instructions for its use on GitHub.

How to set up Matomo as a sub-domain via a CNAME

If neither of the above methods are viable, you can also configure Matomo to load from another URL at the domain level. A CNAME is a type of DNS record that can deliver a specified URL through another domain.

The exact method for creating a CNAME record will vary depending on your domain registrar or DNS hosting service. However, you will need to go into the DNS configuration for your chosen domain and then add the specific settings you will need to configure are:

  • Record Type: CNAME
  • Name: The sub-domain you’d like to use e.g. stats for stats.example.com
  • Target/Value: Enter your Matomo URL, e.g. https://demo.matomo.cloud/
  • TTL: You can usually accept the default suggestion

The domain stats.example.com will display the content from demo.matomo.cloud, but the browser address bar and referrer will show as stats.example.com.

Required Step: Configure Matomo to Accept New URLs

Whichever method you use, once you have created the instructions for your server to access Matomo at the new URLs, you also need to confirm this new configuration with Matomo. Find the config.ini file for your Matomo installation and add each of the domains to your trusted hosts on a new line by with the following code, replacing the domains with your relevant domain.

trusted_hosts[] = "example.com"
trusted_hosts[] = "example.org"

When setting up the tracker for each of the websites you have configured, you can now use the relevant path for each site. In this example:

  • example.com/stats
  • example.org/stats

Note: If you are using Matomo Cloud and would like to configure a CNAME record, reach out to support through your dashboard and they should be able to configure your new trusted host name.