My gateway Plugin:
<?php
if($modx->context->get(‘key’) != “mgr”){
//grab the current domain from the http_host option
switch ($modx->getOption(‘http_host’)) {
case ‘example1.de’:
case ‘www.example1.de’:
$modx->switchContext(‘web’);
$modx->setOption(‘cultureKey’, ‘web’);
break;
case ‘example2.de’:
case ‘www.example2.de’:
$modx->switchContext(‘pm’);
$modx->setOption(‘cultureKey’, ‘pm’);
break;
case ‘example3.de’:
case 'www.example3.de ':
$modx->switchContext(‘sa’);
$modx->setOption(‘cultureKey’, ‘sa’);
break;
}
}
My htaccess:
Options +FollowSymlinks
Options -MultiViews
RewriteEngine On
RewriteBase /
# Rewrite domain.com -> www.domain.com -- used with SEO Strict URLs plugin
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} (.+)$
RewriteRule ^(.*)$ http://www.%1/$1 [R=permanent,L] .
# Prevent rewrite the .well-known directory used by LetsEncrypt by rules below of this rule
RewriteRule "^\.well-known/" - [L]
RewriteRule "/\.|^\.(?!well-known/)" - [F]
#Babel
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(sa|pm|web)/favicon.ico$ favicon.ico [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(sa|pm|web)/assets(.*)$ assets$2 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(sa|pm|web)?/?(.*)$ index.php?cultureKey=$1&q=$2 [L,QSA]
The page preview of example1.de and example2.de works without any problems. But as soon as I try to view any page from example3.de, I get the 404 page from the first context. Independent from the template.
My Hosting is all-inkl.com an all 3 domains root in the same folder with php 7.3.
The friendly url rule from the default .htaccess-file should be sufficient.
# The Friendly URLs part
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
Also, in your gateway plugin the line
$modx->setOption('cultureKey', 'web');
doesn’t make much sense. The “cultureKey” should be a language code like “de” or “en” and is not the same as your context-key. If all your domains have the same language, then you don’t need this line.
Reiterating what Halftrainedharry said: base_url should just be a /.
And I think you are confusing culture keys with contexts. You can remove the culture_key setting as it is incorrect and it doesn’t look like you’re creating a multilingual site. (If you are, then this should be set to an actual language code not the name of the context.)
You can add an error page for each context with the error_page setting. Just set to the id of each error page in the same way you have site_start.
As far as I can recall, when using XRouting, you cannot view unpublished pages on the additional contexts even when logged in as super admin. There is a workaround somewhere but I have never implemented it. So that may be why you are seeing the 404s.
Thank you, the error was indeed in the base_url. I have set this as Halftrainedharry said to “/” and now the context can be called.
I had used the CultureKey for calling individual chunks, so for example [[$footer_[[++cultureKey]]]] - “footer_pm”. That’s why I had formulated that. But I’d rather use an [[*context-key]] for that.
This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.