Simple Machines Community Forum

SMF Support => SMF 1.1.x Support => Topic started by: rebus on November 09, 2006, 03:56:56 PM

Title: Multi-domain forum
Post by: rebus on November 09, 2006, 03:56:56 PM
Don't know if this is the right board, but I'm going to try  ;)

I own three domains all pointing to the same forum on the same webspace. It works, but if one doesn't access the forum by the domain recorded in the settings file, it has sometimes login or cookie problems. If I log in by the default domain, no problem. But I would like users to use the domain they prefer. How could this be worked out? Maybe using three different settings files and a kind of script which detects the domain and tells SMF to use the proper setting? If anyone has ideas, thanks in advance  :)
Title: Re: Multi-domain forum
Post by: bank robber on November 09, 2006, 04:45:27 PM
I have the same exact issue.
Title: Re: Multi-domain forum
Post by: Oldiesmann on November 09, 2006, 06:44:20 PM
You will just have to pick one of the three domains and tell your users to use that one.
Title: Re: Multi-domain forum
Post by: Daniel15 on November 09, 2006, 11:36:14 PM
Unfortunately, the cookie can only work on one domain (the 'cookie domain'). As Oldiesmann said, you'll need to pick one of the domains, and tell the users to use that one.
Title: Re: Multi-domain forum
Post by: rebus on November 10, 2006, 05:01:52 AM
Yes, but that was exactly what I was trying to avoid. No workaround possible? Not even using different settings dinamically?
Title: Re: Multi-domain forum
Post by: Ben_S on November 10, 2006, 07:38:31 AM
Is there a reason why you really really need to do this, you are better off picking one and using that alone for all sorts of reasons, not least search engine positioning.
Title: Re: Multi-domain forum
Post by: rebus on November 10, 2006, 08:22:26 AM
Thanks. I don't really really need that but, if there is a way to do it, I'd like it, because the different domains were chosen by users and they want to use the one they chose. That's all  :)
Title: Re: Multi-domain forum
Post by: Neol on November 10, 2006, 08:30:25 AM
Webhosting talk forum did it.

http://www.webhostingtalk.com/index.php

http://www.webhosting-talk.com/index.php

Look at the board:
http://www.webhostingtalk.com/forumdisplay.php?f=1

http://www.webhosting-talk.com/forumdisplay.php?f=1

Any idea how they did it?

Title: Re: Multi-domain forum
Post by: Ben_S on November 10, 2006, 08:32:36 AM
You could probably do something like

$boardurl = $_SERVER['HTTP_HOST'].'/forum';

In your Settings.php
Title: Re: Multi-domain forum
Post by: rebus on November 10, 2006, 10:45:55 AM
Quote from: Ben_S on November 10, 2006, 08:32:36 AM
You could probably do something like

$boardurl = $_SERVER['HTTP_HOST'].'/forum';

In your Settings.php

Thanks a lot! It almost works but gets the URL doubled, something like "http://www.domain.com/forum/www.domain.com/forum"

???
Title: Re: Multi-domain forum
Post by: Ben_S on November 10, 2006, 11:27:00 AM
Hmm in that case try something like

if($_SERVER['HTTP_HOST'] == 'www.firstdomain.com')
    $boardurl = 'http://www.firstdomain.com/forum';
elseif($_SERVER['HTTP_HOST'] == 'www.seconddomain.com')
    $boardurl = 'http://www.seconddomain.com/forum';
elseif($_SERVER['HTTP_HOST'] == 'www.thirddomain.com')
    $boardurl = 'http://www.thirddomain.com/forum';
else
    $boardurl = 'http://www.firstdomain.com/forum';
Title: Re: Multi-domain forum
Post by: Daniel15 on November 10, 2006, 10:06:10 PM
Quote from: rebus on November 10, 2006, 10:45:55 AM
Quote from: Ben_S on November 10, 2006, 08:32:36 AM
You could probably do something like

$boardurl = $_SERVER['HTTP_HOST'].'/forum';

In your Settings.php

Thanks a lot! It almost works but gets the URL doubled, something like "http://www.domain.com/forum/www.domain.com/forum"

???
I think it should have been:
$boardurl = 'http://'.$_SERVER['HTTP_HOST'].'/forum';
;)
Title: Re: Multi-domain forum
Post by: SleePy on November 10, 2006, 11:06:46 PM
I came across the same problem..

I solved mine this way..


//$boardurl = 'http://mydomain.com/forum'; # URL to your forum's folder. (without the trailing /!)
$siteurl_1 = 'mydomain.com';
$siteurl_2 = 'myotherdomain.com';

$boardurl = 'http://' . ($_SERVER['HTTP_HOST'] == $siteurl_2 ||  $_SERVER['HTTP_HOST'] == 'www.'.$siteurl_2 ? $siteurl_2 : $siteurl_1 ) . '/forum'; # URL to your forum's folder. (without the trailing /!)


Also..
I think this might be a future feature or something..

Code ('Subs-Auth.php') Select

// Any alias URLs?  This is mainly for use with frames, etc.
if (!empty($modSettings['forum_alias_urls']))
{
$aliases = explode(',', $modSettings['forum_alias_urls']);

$temp = $boardurl;
foreach ($aliases as $alias)
{
// Fake the $boardurl so we can set a different cookie.
$alias = strtr(trim($alias), array('http://' => '', 'https://' => ''));
$boardurl = 'http://' . $alias;

$cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));

if ($cookie_url[0] == '')
$cookie_url[0] = strtok($alias, '/');

setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0], 0);
}

$boardurl = $temp;
}


I added the variable to my modsettings file and gave it a text string.. Set it up by following what the code was doing.. But it didn't work :(.. wish it would.. Would be cool to have my cookies across my domains..
Title: Re: Multi-domain forum
Post by: Oldiesmann on November 10, 2006, 11:44:59 PM
Interesting find... I'll have to play with that sometime to see what I can get out of it.
Title: Re: Multi-domain forum
Post by: SleePy on November 10, 2006, 11:50:19 PM
lol.. Hopefully you get better luck than I did.. I wasn't able to get any affect out of it.. if you want I can hook you up on my site to play with it, I got 3 domains... ;)
Title: Re: Multi-domain forum
Post by: Ben_S on November 11, 2006, 10:45:57 AM
Quote from: Daniel15 on November 10, 2006, 10:06:10 PM
Quote from: rebus on November 10, 2006, 10:45:55 AM
Quote from: Ben_S on November 10, 2006, 08:32:36 AM
You could probably do something like

$boardurl = $_SERVER['HTTP_HOST'].'/forum';

In your Settings.php

Thanks a lot! It almost works but gets the URL doubled, something like "http://www.domain.com/forum/www.domain.com/forum"

???
I think it should have been:
$boardurl = 'http://'.$_SERVER['HTTP_HOST'].'/forum';
;)

Doh you are right, completly forgot about the http://
Title: Re: Multi-domain forum
Post by: rebus on November 13, 2006, 11:44:42 AM
Both Ben_S and Daniel codes seem to work... thanks a lot to all of you!!  :)