VirtualHost with Joomla - Switch live site from localhost to debugdomain

Forum closed, please submit your tips and tricks to: http://docs.joomla.org/Category:Tips_and_tricks
Locked
Basdub
Joomla! Apprentice
Joomla! Apprentice
Posts: 36
Joined: Sun Apr 29, 2007 3:24 am
Contact:

VirtualHost with Joomla - Switch live site from localhost to debugdomain

Post by Basdub » Fri Aug 03, 2007 1:36 pm

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

Code: Select all

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


to

Code: Select all

$mosConfig_live_site = getLiveSite();  //'http://localhost/myvirtualdirectory';
At the bottom of the file and BEFORE the php closing bracket "?>", add the following function:

Code: Select all

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;

}
Of course, PHP expert can modify this function to make it look even better.

-----------------

With Apache, if you have set you VirtualHost to "/virtualdirectory" in the httpd.conf file, it will also work.
Sebastien Dube
***** Manual signatures are NOT allowed ********** Manual signatures are NOT allowed ********** Manual signatures are NOT allowed ********** Manual signatures are NOT allowed *****_

You want to offer professional web service(s) through paid subscription? Visit http://www.webservicesgateway.com

Locked

Return to “Submit Your Suggested Tips & Tricks to Docs.joomla.org now please.”