Skip to content

Instantly share code, notes, and snippets.

@patrickatwsrn
Last active July 31, 2022 14:09
Show Gist options
  • Save patrickatwsrn/ff247034047d6d63b3dfa8f47fe4f361 to your computer and use it in GitHub Desktop.
Save patrickatwsrn/ff247034047d6d63b3dfa8f47fe4f361 to your computer and use it in GitHub Desktop.
Notes on setting up a multi context modx page

Notes on setting up a multi context modx page

Important This is work in progress and FAR away from completed.

Scenario one: Multiple subdomains

Use case:

I want to have two contexts:

  • Homepage: resources handling actual content
  • Static: resources handling static content like css, js, layout images.

Plesk setup

  1. Create a subdomain and point it to the directory of the parent domain.
  2. Create the followg resources inside your new contexts (see screenshot below)

image

  1. Create a new context and add the following settings
key value
base_url /
error_page 13
http_host static.relaunch.example.com
site_name Static Files
site_start 10
site_status No
site_url https://static.example.com/
site_unavailable_page 14
  1. At this point you should see your maintenance pageIf you open

General ContextRouter Discussion

If you want to redirect a request to a specific context, you need a plugin that triggers on OnHandleRequest.

You have several options:

  1. Write your own router.
  2. Install a plugin that does the job:
  • XRouting - Does Domains, Subdomains and Folder
  • ContextRouter - Outdated, use XRoutung instead
  • Gateway Manager - Comes with an interface that helps you to setup mandatory context settings

Discussion - Additional contexts and site_status = 0

If you set the site_status of a context to 0 (maintenance mode), you can only see it if you have logged into this context.

This means, that if you logged into the main domain manager at example.com, you can see all pages related to this context (usually web) even if your site_status is 0. If your site_status is 1, you can still also see unpublished resources.

If you try to see an unpublished page from another context, or if your whole context is under maintenance, then you see your maintenance page instead. If your site_status is 1, you can still not see unpublished resources.

One way to solve this is ito log into the other contexts as well (static.example.com/manager).

There should be a simpler solution, but I haven't found it sofar.

Discussion: Session less contexts

If a context doesn't need any personalization, you may want to set this contexts session_enabled to 0.

Important Don't add this settiing directly to your system settings, as this will prevent you from accessig the manager. Always add this setting to a contexts settings.

Read more: https://modx.com/blog/new-for-2.2.1-session-less-contexts

This should help, but it doesn't: https://docs.modx.com/current/en/building-sites/settings/session_cookie_domain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment