The XML sitemap file doesn't need to be called sitemap.xml
. You can call it anything you like. eg. sitemap-aaa.xml
.
This is a machine readable file, so you shouldn't necessarily be concerned about what the URL looks like.
However, if you specifically wanted www.example.com/sitemap.xml
and aaa.example.com/sitemap.xml
to be accessible and refer to different files, despite your subdomains pointing to the same place, then you could rewrite the URL. You would still need a sitemap-aaa.xml
(or similar) file stored on the filesystem.
For example, using an Apache .htaccess
file (in the document root) with mod_rewrite:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(aaa|bbb)\.example\.com
RewriteRule ^sitemap\.xml$ sitemap-%1.xml [L]
The above would internally rewrite a request for aaa.example.com/sitemap.xml
or bbb.example.com/sitemap.xml
to sitemap-aaa.xml
and sitemap-bbb.xml
respectively.
You could consider storing these files in a separate directory and blocking direct access to that directory.
However, as mentioned above, since XML sitemap files can be named (and stored) anything you like, there would not seem to be an obvious need to do this.
Providing both subdomains are validated in GSC, you can also have a single sitemap that contains the URLs from both subdomains. (Works with Google at least: https://webmasters.googleblog.com/2007/10/dealing-with-sitemap-cross-submissions.html)