Context routing subdomains and domains

hi
i got this to workl on a site that I did a while ago, but on a new install it is not working I can not figure out why

I have a domain, and a parked domain. the parked domain redirects to the domain

so A.com and B.com and B.com is a parked domain under A.com and redirects there.

What I used to do is just create a new context, then add

base_url: /
http_host: B.com
site_start: 11
site_url: https://B.com/

and it would just work.

I also installed smartRouting, but still no luck. also no errors…

so what happens is it just redirects to the 404 page of the web cotnexxt however it maintains the url of the original query. ie if I go to B.com it displays the 404 in the web ir A.com context however it still shows B.com in the url…

not working. anyone got tipes

Did you try to debug what happens during the request, as described in the documentation under “Troubleshooting”?

i did i am using

only error i am getting though is core/src/Revolution/modLinkTag.php : 108) Bad link tag [[~9]] encountered id 9 is the main id in the new context ie B .com. debug is on smartrouting.allow_debug_info 1 and I also tried ?smartrouting-debug=1 at the end but not workign I also reinstalled plugin and tried to make my own simple snippet. maybe its an apache issue? however other older site on same server works fine. maybe i redo the context

If you set
smartrouting.allow_debug_info to Yes
and
smartrouting.show_no_match_error to No
and
request the URL https://B.com?smartrouting-debug=1,
what is the output you get in the browser?

B.com?smartrouting-debug=1 redirects me to the default site_start page of context A .com when I do A.com?smartrouting-debug=1 it takes me to default 404 on context A.

if i redirect B.com context to 404 = site_start of context B and i enter a url that does not exist I can access the b.com page. So I guess. Therfore I can create a work around with a redirect. But I still no idea why it does that

I’m so confused!


So your default “web” context is for A.com, right?
And then you have a second context for B.com (with the context settings posted above)?

In your document root, you have a .htaccess file with these lines.

RewriteEngine On
RewriteBase /

# The Friendly URLs part
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

Is there anything else in .htaccess that would affect a request to B.com?


If this .htaccess is executed, index.php (in the document root) runs and MODX is initialized. Then on the event “OnHandleRequest”, SmartRouting should switch the context if necessary (based on the requested host → $_SERVER['HTTP_HOST']).

What is the content of the cache file core\cache\smartrouting\contextmap.cache.php?

  • So your default “web” context is for A.com, right? Correct web
  • And then you have a second context for B.com (with the context settings posted above)? Correct
  • htaccess correct - I have nothingh else in the htaccess i stripped all for trouble shooting

smartrouting is not caching there is no smartrouting folder.
i defintaly indstalled I (even reinstalled twice) and I can see it under plugins.

i am guessing smartrouting is not actually running eventhough its installede which is why i am having issues

So do you have other plugins, that run before the SmartRouting plugin and may interfere?

To check, go to :gear: → System Settings → tab “System Events” in the MODX manager.
Use the “Search by event name…” field to filter the grid.
On the events OnMODXInit and OnHandleRequest, are there any other plugins listed (column “Plugins”) that run and may act as a context router?

OnMODXInit SmartRouting, ClientConfig

OnHandleRequest,ClientConfig, SEO Suite, VersionX

Why does the SmartRouting plugin run on the event OnMODXInit and not on the event OnHandleRequest?

What version of SmartRouting and MODX are you using?

no idea I installed it with default settings? what should it be? its version 1.0.1

When I install SmartRouting version 1.0.1-pl on MODX 3, the plugin runs on these events (as defined in the installation config):

I can’t find OnMODXInit anywhere in the code of this extra, nor does the plugin execute any code on this event.

thanks i reinstalled it and now its like above, however sitll not redirecting :sleepy:

Do you now get the debug output from SmartRouting and can see the cache file core\cache\smartrouting\contextmap.cache.php?

still nothing in cache folder so really dont know maybe I must reinstall everything incl cms and try again

If you add a custom plugin that runs on the event OnMODXInit with code like this

<?php
switch($modx->event->name) {
    case 'OnMODXInit':
        if($modx->context->get('key') != "mgr"){
            $host = $modx->getOption('http_host');
            $url = $modx->getOption('site_url') . $_REQUEST[$modx->getOption('request_param_alias', null, 'q')];
            
            $modx->log(modX::LOG_LEVEL_ERROR, "Request to host = {$host} | url = {$url}");
        }
        break;
}

and then request a page in either context.
Does the URL get logged to the MODX error log? Is the output correct?

nothing in the log unfortunatly

reinstalled modx and uninstalled smartrouting and I am getting the following errors trying to access a.domain and b.domain. i am now getting [2024-09-19 14:14:27] (ERROR @ /usr/www/users/xxxxx/a.domain/core/cache/includes/elements/modx/revolution/modplugin/21.include.cache.php : 8) Request to host = a.domain | url = https://a.domain
[2024-09-19 14:14:30] (ERROR @ /usr/www/users/xxxxxxxxx/a.domain/core/cache/includes/elements/modx/revolution/modplugin/21.include.cache.php : 8) Request to host = a.domain | url = https://a.domain

So are you saying that when you request B.com, then in the MODX error log the output from the plugin is “Request to host = A.com” (instead of B.com)?

thaks alot for your help harry, in the end I reinstalled modx and i reinstalled smartrouting from scratch and i manually copied over the content from my other side. as that was quicker than to figure out what was not working. its working now on a fesh install. i really do not know what went wrong with the previous one.