I have TWO separate domains pointing to one joomla installation and it appears to be working fine so far. So, for instance, if I go to www.mysite1.com it works fine. Then, if I go to www.mysite2.com it will “redirect” to www.mysite1.com but still keep the “www.mysite2.com” URL intact in the browser, which is exactly what I want. So, so far so good.
However, I want to be able to simply change the top header image (.jpg image) to reflect the current URL the visitor is under. So, in my template I want it to be like this:
This line is wrong for several reasons, mostly that it does not start or end in any valid way. You need to start with something - eg. echo or $var =. You can’t start with a full stop.
Do you have php displaying errors? If not you can add it at the start of your script, its helpful because it tells you the type of error and the line number it occurred on.
Actually, I was messing with it a little bit more so that I could change more than just a single image and came up with this based on your code and a mix of joomla code:
<?php
$domain = $_SERVER['SERVER_NAME'];
if ( $domain == "www.site1.com" ) { ?>
OUTPUT HTML FOR SITE 1 HERE
<?php }
elseif ( $domain == "www.site2.com" ) { ?>
OUTPUT HTML FOR SITE 2 HERE
<?php } ?>
Now, that seems to work great so far. But how would I extend the above code to work with 3, 4, or even 5 domains?
Thanks again for your help with this and this is probably the biggest thing I have learned in the last 6 months - so, once again, THANKS!
Essentially, the function “$_SERVER[‘SERVER_NAME’]” will get the domain name, then you’re just setting the image to use as “$image”, then echo-ing it out as part of your img.
Should be enough to point you in the right direction anyway.
<?php
$domain = $_SERVER['SERVER_NAME'];
if ( $domain == "www.site1.com" ) { ?>
OUTPUT HTML FOR SITE 1 HERE
<?php }
elseif ( $domain == "www.site2.com" ) { ?>
OUTPUT HTML FOR SITE 2 HERE
<?php }
elseif ( $domain == "www.site3.com" ) { ?>
OUTPUT HTML FOR SITE 3 HERE
<?php } ?>
You can do as many } elseif () { statements as you need.
You could also do a switch statement which I think is a bit tidier for longer control blocks.
$domain = $_SERVER['SERVER_NAME'];
switch ($domain)
{
case 'www.site1.com':
echo 'site 1';
break;
case 'www.site2.com':
echo 'site 2';
break;
case 'www.site3.com':
echo 'site 3';
break;
}
Okay, I have run into a new problem…I am trying to use the domain name code here:
…I am using it to attempt to change the title as well as the META description and keywords of the page depending on the domain the user is coming from.
But when I try to insert the custom code into the following code…I get a PHP error. Here is the code I need to edit.
I tried to edit to by doing the following, but again got a PHP error from doing this:
$strHtml .= $tab.'<title>'
?>
<?php
$domain = $_SERVER['SERVER_NAME'];
if ( $domain == "www.site1.com" ) { ?>
CUSTOM META TITLE FOR SITE 1
<?php }
elseif ( $domain == "www.site2.com" ) { ?>
CUSTOM META TITLE FOR SITE 2
<?php } ?>
<?php
.htmlspecialchars($document->getTitle()).'</title>'.$lnEnd
******code continues on from here...
As you can tell, I am VERY new to PHP…in fact, I would say I have little if any knowledge of PHP but have a lot of experience in HTML and CSS, which is obviously not helping me here.