Skip multisite CMS prefix for certain pages

I’m building a multilingual website, I have 2 sites set:

English with prefix “/en”
Spanish with prefix “/es”

And I want to create a multilingual sitemap for it, the first thing I need is to skip the prefixes in the URL for the sitemap pages.
I have a folder inside my /pages directory called “sitemaps”, inside it I will create different sitemaps and declare them as XML, the code looks something like this:

url = "/sitemap-services.xml"
title = "Sitemap for services"

[collection services]
handle = "Agency\Service"

[sitePicker]

==
<?php
function onStart() {
    $this->setResponseHeader('Content-Type', 'application/xml');
}
?>
==
{##}

The problem is that this generates 2 versions of the sitemap:
mysite.com/en/sitemap-services.xml and mysite.com/es/sitemap-services.xml

I usually use Routes and views in plugins to create static sitemaps and skip the prefixes, but in this case, the sitemaps are dynamic and I’m creating them inside the theme to use the twig variables from Tailor and other plugins I use.

This is the method I usually use:

Route::get('sitemap-services.xml', function(){
    return Response::view('uno.agency::sitemap-services')->header('Content-Type', 'text/xml');
});

Is there a way to return a page from my theme with this method? Or is there any other way to apply this in the way I need?

Hello @EMAD08

Assuming you are using the Multisite feature in v3, there is a middleware class you can use to apply the current context. Take a look at the System\Middleware\ActiveSite class.

Hopefully it helps!

1 Like

Even if there is a middleware to bypass the mulsite url rewrite, I think it could be a nice addition to add it to the core CMS > ressources component to avoid writing a plugin just for that.

It would be really useful for example to write a robots.txt file directly from the backoffice editor, the same way we can not write sitemap thanks to an editor page + tailor blueprint.