JoomFish with multiple domains trick

I know lot of people or LOVE or HATE Joomla!, specially Joom!Fish. If you are like me, you’ll hate for sure. WHY? Because it’s complicated. Lots of data on different locations. Joom!Fish sometimes force you to translate default language ?!?!? And with other languages it’s also sometimes pain in the ass. But let’s say that we have to use it because it is one of the best components that kind out there.

Let’s begin!

Let’s say you want to do SEO magic, improve your rankings by buying new domain with keywords for every language on a website. That’s  smart thing to do only if you really will update content and make it unique for every language, which means no duplucated content or content that is on different language. Tricky stuff with Joom!Fish is that you have few choices when there’s no translation. Joom!Fish will serve content based on your setting for non-existing content, it will server original content, text and some other combinations of both.

But the thing is how you can make it all work with different domains and one installation of Joomla!.

Let’s setup vhost first, example will be “babyseal-shoes” 🙂 . This is just an example of vhost, not MUST DO… Just watch for ServerAlias:


    ServerAdmin webmaster@localhost
    ServerName www.babyseal-shoes.com
    ServerAlias www.babyseal-cipele.hr
    ServerAlias www.seehundbaby-schuhe.de
    DocumentRoot /var/www/vhosts/babyseal-shoes

       Options Indexes FollowSymLinks MultiViews
       AllowOverride All
       Order allow,deny
       allow from all

    ErrorLog /var/log/apache2/error_babyseal-shoes.log
    LogLevel warn
    CustomLog /var/log/apache2/access_babyseal-shoes.log combined

As you can see ServerAlias contains keywords meaningful (maybe, i don’t speak german 🙂 ) for that domain, but all point to same location on server. In order all of this to work we will change 2 files.

First file is located under modules/mod_jflanguageselection/helper.php. Open it with fav text editor and look for a function _createHRef () and find this$db->_profile($pfunc); and add the code after it but BEFORE return $url.

  	if($code == 'en'){
		$url = str_replace($_SERVER['HTTP_HOST'], "www.babyseal-shoes.com", $url);
		}
	if($code == 'hr'){
		$url = str_replace($_SERVER['HTTP_HOST'], "www.babyseal-cipele.hr", $url);
		}
	if($code == 'de'){
		$url = str_replace($_SERVER['HTTP_HOST'], "www.seehundbaby-schuhe.de", $url);
		}

After _createHRef() function is one function that we will modify, it’s function _createHRef2().
Add exactly the same code before return $url;

	if($code == 'en'){
		$url = str_replace($_SERVER['HTTP_HOST'], "www.babyseal-shoes.com", $url);
		}
	if($code == 'hr'){
		$url = str_replace($_SERVER['HTTP_HOST'], "www.babyseal-cipele.hr", $url);
		}
	if($code == 'de'){
		$url = str_replace($_SERVER['HTTP_HOST'], "www.seehundbaby-schuhe.de", $url);
		}

Second step is really hardcoded, which i don’t like, but i had to make it fast so i did it this way. I know that the same result can be accomplished with .htaccess but I don’t know how to do it. If somebody knows how next stem create in htaccess please post it in comment.

Now open index.php file in root directory and add following

if(count($_GET) == 1 OR count($_GET) == 0 ){
if ($_SERVER['HTTP_HOST'] == 'www.babyseal-cipele.hr') {
    if ($_GET['lang'] == 'de') {
        header(sprintf("Location: http://%s/%s", 'www.seehundbaby-schuhe.de', $_GET['lang']), true, 301);
    }
    if ($_GET['lang'] == 'en') {
        header(sprintf("Location: http://%s/%s", 'www.babyseal-shoes.com', $_GET['lang']), true, 301);
    }
    if ($_GET['lang'] == '' AND strlen($_SERVER["REQUEST_URI"]) <= 4  ) {
        header(sprintf("Location: http://%s/%s", 'www.babyseal-cipele.hr', 'hr'), true, 301);
    }
}
if ($_SERVER['HTTP_HOST'] == 'www.babyseal-shoes.com') {
    if ($_GET['lang'] == 'de') {
        header(sprintf("Location: http://%s/%s", 'www.seehundbaby-schuhe.de', $_GET['lang']), true, 301);
    }
    if ($_GET['lang'] == 'hr') {
        header(sprintf("Location: http://%s/%s", 'www.babyseal-cipele.hr', $_GET['lang']), true, 301);
    }
    if ($_GET['lang'] == '' AND strlen($_SERVER["REQUEST_URI"]) <= 4 ) {
        header(sprintf("Location: http://%s/%s", 'www.babyseal-shoes.com', 'en'), true, 301);
    }
}
if ($_SERVER['HTTP_HOST'] == 'www.seehundbaby-schuhe.de') {
    if ($_GET['lang'] == 'hr') {
        header(sprintf("Location: http://%s/%s", 'www.babyseal-cipele.hr', $_GET['lang']), true, 301);
    }
    if ($_GET['lang'] == 'en') {
        header(sprintf("Location: http://%s/%s", 'www.babyseal-shoes.com', $_GET['lang']), true, 301);
    }
if ($_GET['lang'] == '' AND strlen($_SERVER["REQUEST_URI"]) <= 4 ) {
        header(sprintf("Location: http://%s/%s", 'www.seehundbaby-schuhe.de', 'de'), true, 301);
    }

}
}

Probably some of you will ask what is this for

strlen($_SERVER["REQUEST_URI"]) <= 4

Well, without this page will be constantly redirected to domain.com/$lang because of a strange thing. When i did var_dump($_GET) of this url domain.com/en/something_written $_GET was EMPTY… in that case no lang param and it will redirect all the time, that’s why i made that one more condition, in order this trick to work.

Uf, long post, but i hope you will see it useful.

cheers 🙂

Advertisements

24 thoughts on “JoomFish with multiple domains trick

  1. Hi! Thanks for this trick! I was looking for a solutions to the duplicate domain issue.
    I have a question though.
    I have two domains: dare2express.nl (which should show the dutch website) and dare2express.com (which should show the English website). The .nl works fine. This only shows the dutch website, but the .com also shows the Dutch website. Once the Eglish language is selected, it shows only the English pages. Is there something else I should change? Maybe something in jfrouter?

  2. Hi,
    i checked both of your websites, and it seems that u missed something.
    In this post there is 4 blocks of code, 1st is related to VCONF of apache, 2nd and 3rd are related to this file ‘modules/mod_jflanguageselection/helper.php’
    and 4th is related to index.php file in root directory. All blocks are important but i think if you don’t do 2nd and 3rd block redirection will not work, because these blocks do replacement of links, while 4th block is doing redirection when links are not accessed from main site or someone is entered dare2express.nl/en website which have to be redirected to dare2express.com/en.
    Please check again steps and write if you fail to do it. I’ll attach then files that u have to copy in order to work.

    cheers 🙂

  3. Hi!
    Thanks for your reply!
    I am sorry I could not respond earlier as I was on holiday. I again repeated all the steps. Except for the first step. I don’t know which file to change.

    The result is the same. dare2express.com does not point to the English site.

    I hope you can help me.

    • Sorry for not answering before. Today i checked your website and i saw that redirections are working 🙂 im happy that this post helped you.

      Cheers
      Daniel

      • No problem! Thanks for looking 🙂

        There is still one problem. If I go to http://www.dare2express.com, I get the Dutch version of the website instead of the English version. The language selection works perfectly. If I select English, the .com site opens and Dutch, the .nl site opens.

        Only the initial language selection does not work for the .com site. Could it be because I live in the Netherlands that it automaticly selects Dutch as the language? What happens if you go the .com site?

      • Hei,
        When you enter http://www.dare2express.com it should redirect you to http://www.dare2express.com/en.
        The same is with dutch site. Reason you have dutch translation ob English domain is because JoomFishe’s default language is dutch. Check again post, look last come block and last few lines are server response without language parameter , in same line is strlen (something =< 4). Be sure that u setup that line correct.

        Post here link from pastebin with content of your file if you have problem.

        Cheers,
        Danijel

  4. Thank you for this solution. After hours of searching I could solve my problem. Greetings from Switzerland. Cheers, Michael

  5. Hello Wossy,

    Thanks for this solution, i search it for some months but… it doesn’t work for me, i check each point and i think i do all needed modifications. The domain is always the same. Do you think that something else can block these redirections on my server configuration ?

    Thanks
    Thomas

    • Looks like the only thing that does not work is the Home button. No matter which language is on when you click it goes to original language.

      • Bok Marko,

        To se desava zato sto JoomFish sprema cookie za defaultni jezik. Vec duze vrijeme ne koristim Joomla! a i nisam upoznat sa novim ( ako uopce postoje ) verzijama JoomFish-a.
        Mozes probati forsirati da jezik bude u URL, a i koristiti .htaccess da napravi redirect na odredjeni jezik ako netko upise adresu bez jezika.

        Nadam se da sam ti pomogao 🙂
        Ako zapnes postaj ovdje komentar 🙂

        Pozz

      • Hvala ti. Uspio sam riješiti stvar. Sve radi, ali moram priznat da sam malo skeptičan što će biti sa SEO sada kada sajt podijelim na tri domene.
        Pretpostavljam ako svaki jezik bude imao svoj tekst neće biti dupliciranja pa će biti ok.
        Živi bili pa vidjeli.

        Hvala

  6. THanks! Greeting from Mongolia 🙂 Im not good at php.
    I used above code but it doesn’t work. maybe i did something wrong.
    Server Alias
    if($code == ‘en’){
    $url = str_replace($_SERVER[‘HTTP_HOST’], “www.centralasiancement.com”, $url);
    }
    if($code == ‘hr’){
    $url = str_replace($_SERVER[‘HTTP_HOST’], “www.centralasiancement.mn”, $url);
    }
    helper.php
    function _createHRef ()
    if($code == ‘en’){
    $url = str_replace($_SERVER[‘HTTP_HOST’], “www.centralasiancement.com”, $url);
    }
    if($code == ‘hr’){
    $url = str_replace($_SERVER[‘HTTP_HOST’], “www.centralasiancement.mn”, $url);
    }
    function _createHRef2 ()
    ….if($code == ‘en’){
    $url = str_replace($_SERVER[‘HTTP_HOST’], “www.centralasiancement.com”, $url);
    }
    if($code == ‘hr’){
    $url = str_replace($_SERVER[‘HTTP_HOST’], “www.centralasiancement.mn”, $url);
    }…

    in index.php
    if(count($_GET) == 1 OR count($_GET) == 0 ){
    if ($_SERVER[‘HTTP_HOST’] == ‘www.centralasiancement.mn’) {
    if ($_GET[‘lang’] == ‘de’) {
    header(sprintf(“Location: http://%s/%s“, ‘www.centralasiancement.com’, $_GET[‘lang’]), true, 301);
    }

    if ($_GET[‘lang’] == ” AND strlen($_SERVER[“REQUEST_URI”]) <= 4 ) {
    header(sprintf("Location: http://%s/%s&quot;, 'www.centralasiancement.mn', 'mn'), true, 301);
    }
    }
    if ($_SERVER['HTTP_HOST'] == 'www.centralasiancement.com') {
    if ($_GET['lang'] == 'de') {
    header(sprintf("Location: http://%s/%s&quot;, 'www.centralasiancement.mn', $_GET['lang']), true, 301);
    }

    if ($_GET['lang'] == '' AND strlen($_SERVER["REQUEST_URI"]) <= 4 ) {
    header(sprintf("Location: http://%s/%s&quot;, 'www.centralasiancement.com', 'en'), true, 301);
    }
    }
    }
    Any Idea? Did i miss something?

    • Hi,

      The example is made for multi-lingual website with capability for 3 languages. I have checked http://www.centralasiancement.com, u have there 2 languages only, and no hr=Croatia, de=Germany 🙂
      You should remove one of the lines (not EN) and replace with mongolian code.

      iif($code == ‘en’){
      $url = str_replace($_SERVER['HTTP_HOST'], “www.centralasiancement.com”, $url);
      }
      if($code == ‘mn’){
      $url = str_replace($_SERVER['HTTP_HOST'], “www.centralasiancement.mn”, $url);
      }
      helper.php
      function _createHRef ()
      if($code == ‘en’){
      $url = str_replace($_SERVER['HTTP_HOST'], “www.centralasiancement.com”, $url);
      }
      if($code == ‘mn’){
      $url = str_replace($_SERVER['HTTP_HOST'], “www.centralasiancement.mn”, $url);
      }
      function _createHRef2 ()
      if($code == ‘en’){
      $url = str_replace($_SERVER['HTTP_HOST'], “www.centralasiancement.com”, $url);
      }
      if($code == ‘mn’){
      $url = str_replace($_SERVER['HTTP_HOST'], “www.centralasiancement.mn”, $url);
      }…
      in index.php
      
      if(count($_GET) == 1 OR count($_GET) == 0 ){
      if ($_SERVER['HTTP_HOST'] == 'www.centralasiancement.com') {
          if ($_GET['lang'] == 'mn') {
              header(sprintf("Location: http://%s/%s", 'www.centralasiancement.mn', $_GET['lang']), true, 301);
          }
          if ($_GET['lang'] == '' AND strlen($_SERVER["REQUEST_URI"]) <= 4 ) {
              header(sprintf("Location: http://%s/%s", 'www.centralasiancement.com', 'en'), true, 301);
          }
      }
      if ($_SERVER['HTTP_HOST'] == 'www.centralasiancement.mn') {
          if ($_GET['lang'] == 'en') {
              header(sprintf("Location: http://%s/%s", 'www.centralasiancement.com', $_GET['lang']), true, 301);
          }
          
      	if ($_GET['lang'] == '' AND strlen($_SERVER["REQUEST_URI"]) <= 4 ) {
              header(sprintf("Location: http://%s/%s", 'www.centralasiancement.mn', 'mn'), true, 301);
          }
      
      }
      }
      

      I think this should work…. check it against original example and see what i have changed 🙂

      Keep me informed…
      Cheers

      • thanks for your replied 🙂
        I’m sorry I have misunderstood what you have written.
        I’m using .htaccess. Is there any way to do it using htaccess?

      • Well it is possible but i didnt manage to do it with .htaccess. If u put that in the code it will work with normal .htaccess that comes with Joomla! If it does not work send me email so we can figure this out 😉

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s