[Joomla1.5] How to implicitly set server's URL?

652 views
Skip to first unread message

Sergiks

unread,
Jun 2, 2011, 3:27:40 AM6/2/11
to joomla-de...@googlegroups.com
Hi all,
is there a way to tell Joomla which URL it is on, instead of what it gets from Apache server configuration?

Situation is that the new site is hosted on a new hosting, configured to serve some domain,
which is not yet switched from the old hosting.

New site is also accessible by its 'technical' domain alias "domain.com.provider-tech.com".
However, as Joonla thinks its on "domain.com" - all links it generates are referencing that domain.

Cannot change Apache settings.

I guess, got to find the first call to JURI object and initialize it with the correct url like JURI::getInstance('http://domain.com.provider-tech.com');
Any workarounds? Core hacks?


Kind regards,
Sergei.

shumisha

unread,
Jun 2, 2011, 4:52:35 AM6/2/11
to Joomla! General Development
HI

You'll find a $live_site variable, currently empty, in Joomla's
configuration.php file. You have to set it up directly in the file,
there is no user interface for it. You must enter a full URL, with no
trailing slash, ie $live_site = 'http://www.mysite.com';
Either include or exclude the www subdomain, based on what is your
selected "main" url.

Rgds

Sergiks

unread,
Jun 3, 2011, 4:15:32 AM6/3/11
to joomla-de...@googlegroups.com
Dear shumisha,

the $live_site variable set to the temp subdomain fixed most links.

The problem is that the <base href="..."> in the output is still unaffected by the $live_site config variable.
I digged into the code and found that this base href is included in JDocumentHTML::render() method,
where the base is retrieved from JURI::base(true)

I added trace outputs like var_dump( JURI::base(true));  right before the "return $data;" last line of the method in html.php to see the value
and found that it dumped an empty string(0) — is it normal?


Sergiks

unread,
Jun 3, 2011, 6:26:59 AM6/3/11
to joomla-de...@googlegroups.com
Is this a bug? Looks like this shouldn't be this way:
JURI ( uri.php), lines 232-235:
if(trim($live_site) != '') {
    $uri =& JURI::getInstance($live_site);
    $base['prefix'] = $uri->toString( array('scheme', 'host', 'port'));
    $base['path'] = rtrim($uri->toString( array('path')), '/\\');

In case $live_site is supplied, there is no path in it, so $base['path'] gets an empty string.
last line (253) of this method:
return $pathonly === false ? $base['prefix'].$base['path'].'/' : $base['path'];
as the method is called from render() like base(true), it returns $base['path'], which is empty.

So, JDocumentHTML::render's call to
$this->baseurl  = JURI::base(true); sets baseurl property to an empty string if $live_site is set.
I couldn't trace it further to find how does the Document's base property gets assigned that wrong value?

However, I found a quick workaround, no hacks, the code goes to the start of the template's index.php:
$document = & JFactory::getDocument();
$document->setBase('http://the.right.temp.domain.here');

Hope this helps someone.

shumisha

unread,
Jun 3, 2011, 7:13:27 AM6/3/11
to Joomla! General Development
This baseurl property is not used to set the base tag. Search instead
for the setBase() method, which is used in the JApplication class.
You'll see it is actualy JURI::current() that is used to set the base
url (as per the actual definition of the base tag).

The actual issue might be in the current() method, as it appears to
not comply with the $live_site setting but instead only use
JURI::getInstance().

This might be worth checking the tracker item and reporting it I think

Rgds
Reply all
Reply to author
Forward
0 new messages