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

    I am defining the path to my CSS files etc like the following

    <base href="[(site_url)]"/>

    <link charset="utf-8" title="CSS" media="screen" type="text/css" href="[(site_url)]assets/templates/theme/css/style.css" rel="stylesheet"/>


    My Domain is .org.uk but I also have .co.uk pointed towards the site.

    My problem is that whatever URL you use to visit the site the CSS path that is built from the [(site_url)] is the .co.uk domain. This does not cause me any problems however I am using some javascript developed by a third party that checks the URL that it is called from so the site_url shoud be .org.uk if thats the URL i used or .co.uk if I used that URL.

    Hope this makes sense.

    Anyone got any ideas or come across this before.


    Thanks
    Adam
      • 10487 MODX Staff
      • 1,535 Posts
      The site_url is being cached with the page and that’s why it doesn’t update when the TLD changes.

      You can circumvent this by creating a snippet called getSiteUrl:
      <?php
      return MODX_SITE_URL;
      

      And then, calling this snippet uncached in place of the [(site_url)]:
      <base href="[!getSiteUrl!]"/>
        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
        • 5948
        • 32 Posts
        Thanks for the reply I will try returning the

        $_SERVER["REQUEST_NAME"]


        This way I should set the base to whatever domain they are using either .co.uk or .org.uk
          • 29774
          • 386 Posts
          $_SERVER["REQUEST_NAME"] will not give you the alias name. You need $_SERVER["HTTP_HOST"], but beware header injection - you could open yourself up to a XSS exploits if you just allow the header to be output to the page.

          <?php
          // array of safe domains
          $domains=array(
          	'www.mysite.co.uk',
          	'www.mysite.org.uk',
          	'mysite.co.uk',
          	'mysite.org.uk'
          	);
          $server = $domains[0];
          foreach ($domains as $key => $value) {
          	if ($value == $_SERVER["HTTP_HOST"]) {
          		$server = $value;
          	}
          }
          return $server;
          ?>
          
            Snippets: GoogleMap | FileDetails | Related Plugin: SSL