Actions

VirtualHost with Joomla

From Joomla! Documentation

It is also related to debugging between localhost or mysitedebugdomainname.com.

Q: Unable to view my site properly from my debug domain name: mysitedebugdomainname.com, only from localhost that it is displayed properly. Is there a way to make the transition automatic!

A: YES!

The 'problem' is related to the variable $mosConfig_live_site. When changing from localhost to mysitedomain.com we assume that your site is going live. Therefore, you want to update the $mosConfig_live_site variable in the configuration file.

If you need to perform other test with a temporary "almost" live site then you would have to change that variable every time.

Now, you could also modify your configuration file like this.

Change this line

    $mosConfig_live_site = 'http://localhost/myvirtualdirectory';

to

    $mosConfig_live_site = getLiveSite();  //'http://localhost/myvirtualdirectory';

At the bottom of the file and BEFORE the php closing bracket "?>", add the following function:

    function getLiveSite(){
    $s = empty($_SERVER["HTTPS"]) ? ''
          : ($_SERVER["HTTPS"] == "on") ? "s"
          : "";
       $proto = explode('/', $_SERVER["SERVER_PROTOCOL"]);
       $protocol = strtolower($proto[0]).$s;
       $port = ($_SERVER["SERVER_PORT"] == "80") ? ""
          : (":".$_SERVER["SERVER_PORT"]);
 
       $getVD = explode('/', $_SERVER['PHP_SELF']);
       if(count($getVD) <=2 ){
          $virtualdir = '';   
       }
       else{
          $virtualdir = '/' . $getVD[1];
       }
 
 
       return $protocol."://".$_SERVER['SERVER_NAME'].$port. $virtualdir;
 
    }