It is possible. Point the subdomain stats.example.com not to the matomo directory, but to a symlink named “matomosymlink” there is linked to the matomo directory. Than you can use stats.example.com and it used the same matomo installation.
An another solution is possible with DNS CNAME (cloaking).
Thanks for a fast answer! Even though it takes more steps (maybe even making a SSL certificate for the stats.example.com subdomain?) your suggested symlink solution sounds like it could work. Have you tried it yourself?
Setting up DNS CNAME is probably a little bit too complicated, for most users …
After sleeping on it and experimenting a bit, rather than making a new stats.example.com sub-domain, it’s simpler to use Apache’s Alias Directive to map a URL to a filesystem location:
The Alias directive allows documents to be stored in the local filesystem other than under the DocumentRoot. URLs with a (%-decoded) path beginning with URL-path will be mapped to local files beginning with directory-path.
These steps did it:
Define an alias in /etc/apache2/mods-available/alias.conf pointing to stats.example.org: Alias "/stats" "/var/www/html/stats.example.org/public_html"
Add trusted_hosts[] = "example.com" in config/config.ini.php to avoid “Warning: You are now accessing Matomo from …” message
Yes, all sub/domains must have a SSL cert, when https is in use. Than it is very simple.
In your Apache’s Alias Directive method, the user must have an access to the apache configuration. The symlink methode is available with typical webhost accounts without apache access.
Works the Apache’s Alias Directive method without a SSL cert for the aliased subdomain?
Yes, my plan was originally to have a subdomain stats.example.com, but I realized that I then needed to create an entire subdomain, generate SSL with lets encrypt, for it, etc. Way too much work.
This is what I meant with “After sleeping on it and experimenting a bit, rather than making a new stats.example.com sub-domain …”. Sorry if it wasn’t clear enough.
So that’s why I decided to use example.com/stats instead, and Apache Alias. It seems to be working well.
Also, the matomo is in /var/www/html/matomo.
The domains points to shes web public folder.
Inside this folders is a symlink named stats.
Both stats symlinks points to the folder with the matomo installation.
Thanks for sharing an alternative solution using symlinks, not requiring SSL.
I did at first consider that solution, but had to drop it, since many CMS’es remove all files and folders during an update.
The benefit of using Apache Alias is that the configuration is persistent. But for more hand-held, or simpler web sites, a symlink in the root could work.
In any case, I feel like there should be a FAQ page (such as How do I configure my server to let Matomo serve HTML files?) about this use case, outlining how to use Matomo with Apache Alias or symlink, using the info we shared here. Something like this?
How do I use a single Matomo installation for different web sites, using the individual domain?
Say you have two (or more) web sites, and want to share a single Matomo installation, with this structure:
It is possible for both https://example.com/stats AND https://example.org/stats to access that single Matomo installation, either using symlinks or Apache Alias to map a URL to a filesystem location.
Since many CMS’es remove all files and folders during an update, the benefit of using Apache Alias is that the configuration is persistent. But for more hand-held, or simpler web sites, a symlink in the root could work.
Using Apache alias
Note: Add the alias in /etc/apache2/mods-available/alias.conf, not in the virtual host file, which doesn’t work. This will add an alias for all domains, so you might want to limit the aliasing by folder.
Define an alias in /etc/apache2/mods-available/alias.conf pointing to the Matomo installation folder, and restart Apache: Alias "/stats" "/var/www/html/matomo"
Using symlink
Create two symlinks pointing /stats in the public web site folder to the Matomo installation folder with these commands: ln -s /var/www/html/example.com/stats /var/www/html/matomo ln -s /var/www/html/example.org/stats /var/www/html/matomo
Final configuration for both Apache Alias and symlink
Add the two web sites in config/config.ini.php to avoid “Warning: You are now accessing Matomo …” message: trusted_hosts[] = "example.com" trusted_hosts[] = "example.org"
In both web sites, point the Matomo tracking URL to example.com/stats and example.org/stats
@ra , its possible. Please wait a week (waiting for other comments here) and than open an new issue as “c: Documentation” in Github.
The label “c: Documentation” is for the matomo documentation pages.
And push a solution with CNAME in your tutorial.
A CNAME-Record (canonical-name-record) in the DNS (domain name system) is like a symlink in the filename system (filesystem).
The CNAME-Record is a domain or a subdomain to which a domain or subdomain points. But its not a Redirect and not a RewriteRule. Its like symlink. The content of an cname-domain is (also) delivered with a cnamed domain.
DNS
Domain: example.com
Name - Record - Value
www - CNAME - www.example.org
The domain www.example.com will display the content from www.example.org, but in the browser address bar is displayed and the referer is always www.example.com.
With HTTPS (SSL) it is necessary, that both domains have a cert.
The term “canonical” is known from HTML link attribute in the head. <link rel="canonical" href="http://example.com/">
With this, the searchbots known, that the original content is published under example.com. With CNAME is this not needed.
CNAME is further named “cloaking” and has a negative image in the internet management.
By the way: Here in Matomo is all DIY. Either you do it, or no one does. I am only a matomo user, not a matomo developer.
Though, as you write, using CNAME is also referred to as cloaking, and can be seen as something nefarious … especially among the privacy oriented.
And since many use Matomo exactly due to privacy concerns, I am not sure it would be a great idea to include it in the FAQ page, should it ever get created … just my 2 cents.
And about getting things done, and this page included in the FAQ documentation: It would seem to me a loss for Matomo, if the developers don’t follow along here in the forum, and if they see something like this issue, adapt it for the documentation, since us users seem to have a need for it.