hi
can the site setting site_url be dynamically set? for example apache is setup for 2 domains, but the modx envurinment isnt setup for 2 domains. can the site_url be set to a snippet, which determines dynamically which domain name is being viewed by the $_SERVER['HTTP_HOST'] ?
i assume if this is setup that this would also need to be changed in other locations? i.e static files etc...???
please advise
Usually, site_url *is* set dynamically based on the URL the user comes in on and all templates have this code to adjust any links:
<base href="[[!++site_url]]" />
The exclamation point is critical if there is more than one domain involved.
If the user will switch from one domain to the other during the session, however, the session data will be lost.
-
☆ A M B ☆
- 24,524 Posts
You can see how this is determined for each page request by looking at the /core/config/config.inc.php file. It uses several $_SERVER values. In some rare cases server configuration can prevent the exposure of these server values, in which case plugins or other methods are needed for MODX to itself determine the incoming request's domain.
You can also put this code on any page to see the site URL at that point:
<p>Site Url: [[!++site_url]]</p>
Be sure you have the uncached base href tag in the template as described above and always use a link tag for internal links. To the home page, for example (assuming the Home page has ID 1):
<a href="[[~1]]">Home</a>