A frequently used practice in MODX is to use a base href tag in templates. This makes creating portable sites, re-usable baseline starting points/Snapshots, and moving from stage to production much more straightforward. It’s also critical for success with MODX’s friendly URL method.
However, if you cache these types of URLs, things can not work as expected or Search Engines indexing the wrong URL.
MODX Cloud allows a site to be accessed by multiple URLs in addition to your custom domain name:
- abc1234.modx.dev is the internal cloud URL
- example.com is a custom domain
To ensure Search Engines and your Visitors see the correct site URL or the site doesn't throw errors, add the following base href tag in your MODX website HTML <head> section above any other things that have relative URLs (e.g., CSS or local JS):
<base href="[[!++site_url]]">
Note: The [[!++site_url]] should always be uncached (i.e., it should be prefixed with the ! (denoting uncached). System setting variables (anything with a "++" token) are stored in memory in MODX. Therefore there is no performance penalty for calling them uncached. Many sites use a cached site_url setting, which results in broken behavior when changing URLs during a site launch.