We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27763
    • 29 Posts
    Hi,

    I have one Modx Evo website with multiple domain names parked on top of it.

    I want to swap the logo image file depending on which domain name used to access the website.

    My snippet works on all pages EXCEPT the homepage. The homepage always shows the logo for the primary domain. Any ideas why?

    <?php
    $domain = preg_replace("/^www\./", "", $_SERVER['HTTP_HOST']);
    
    if ($domain=="andrewrobards.com.au") {
          echo "logo-robards.png";
    }
    if ($domain=="shanahansfp.com.au") {
          echo "logo-shanahans.png";
    }
    ?>


    Primary Domain: andrewrobards.com.au
    Parked Domain: shanahansfp.com.au

    Thanks for any input huh
      • 33968
      • 863 Posts
      Not sure at first impression, but if it’s possible to test this (maybe in your site footer) you will be able to see what the value of $domain is for your home page:
      <?php
      $domain = preg_replace("/^www\./", "", $_SERVER['HTTP_HOST']);
      return $domain;
      
        • 27763
        • 29 Posts
        I should have mentioned that. I have run that test. You can still see it in the footer of the sites.

        $domain returns a different result on the modx homepage then all of the other pages. On the homepage $domain always gives the primary domain even if the secondary domain is typed in. The subpages all work as planned and $domain returns the domain name actually being used.

        Could there be some sort of Modx trickery going on here?

          • 33968
          • 863 Posts
          I think there is some trickery involved for your ’site start’ page so it works from www.domain.com and not www.domain.com/alias. Not sure about Evo though.

          What value is showing up in your base tag?

          You could also try getting the path from here:
          $modx->config['base_path'];
          

          but I suspect you will have the same issue with that too.

          I don’t really have any more ideas at the moment I’m afraid sad

          One thing you should be careful to do here is to include a canonical meta tag on every page that points to the equivalent page on your primary domain, as that will avoid duplicate content issues with search engines thinking you have two sites with identical content.
            • 27763
            • 29 Posts
            Hmmmm..

            $modx->config['base_path'];


            give the path /home/account/public_html

              • 33968
              • 863 Posts
              Sorry, I meant site_url smiley