We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6038
    • 228 Posts
    I’ve got a strange problem with a site i’ve developed where the [(site_url)] seems to vary between two different values.

    I have the site url dropped in the base tag for each page as per normal...
    [tt]<base href="http://www.mydomain.com/"></base>[/tt]

    but sometimes it appears as
    [tt]<base href="http://www.totallydifferentdomain.com/"></base>[/tt]

    The same chunk that holds some html head elements is being used in both cases, but different values are being populated.
    I should mention that the other domain is actually a related domain - an old domain that the site used to be known by, which makes me think it must be some weird DNS flip-flopping.

    So I guess I’m wondering where MODx gets its value for site_url from?
    Is this just the [tt]$_SERVER[’HOSTNAME’][/tt] value?

    I want to report it to the site admin who looks after the hosting, but I’m not sure what to tell him.


    I’m using
    Modx 0.9.6.1p2
    PHP 5.2.3
    Apache 2
    Ubuntu 6.4
      • 33997
      • 150 Posts
      I was having similar problems on 0.9.6.3; I was developing on one domain while the DNS was being populated, and later the site was using partially each domain. Try clearing the cache; it worked for me. What I think was happening was the pages had the old URL saved, and so were populating the <base href> tag with the value that was saved in the cache.
        "Great spirits have always encountered violent opposition from mediocre minds." -Albert Einstein
        • 22303 MODX Staff
        • 10,725 Posts
        MODx uses the $_SERVER[’HTTP_HOST’] to determine this value.

        Most hosts have the web server configured to pass through the HTTP_HOST headers the client requests to get to your web site, and uses those to get to the site; this is a typical virtual hosting configuration in Apache. And if there is more than one way to get to a site (consider even the difference between www.domain.tld and domain.tld), you should consider using .htaccess to ensure only the domain you expect is getting to the site (you can redirect the rest to the proper domain, just like the www- to non-www example provided in the distributed ht.access file) and/or use a non-cacheable snippet to place the base href tag (where the site_name is typically used) in your template. The latter solution allows your site to serve multiple domains while remaining on the requested domain regardless of who requested a page the first time; otherwise, everyone would see the site_url value cached on that page by that first request.
          • 6038
          • 228 Posts
          Thanks for your elucidation, OpenGeek - you are a fount of knowledge.
          I will hardwire the correct domain in the base tag for now, and ask the server admin to look into it...