• Resolved MatthijsdeGraaf

    (@matthijsdegraaf)


    Hi all,

    I have problems creating a .htaccess file that directs the language subdomain to the main page. For instance:

    https://www.domain.com, de.domaian.com, nl.domain.com, fr.domain.com

    I want to serve these pages the same user generated content (so a MU installation is -I think- not an option), but I want the page to be translated accordingly and serve some language based content.

    Does anyone know if it is possible to show the user the main page (which is currently https://www.domain.com) and send a POST/GET to PHP letting the code know that the user is currently on the *.domain.com page? It is important that the subdomain is not rewritten to something like https://www.domain.com/?lang=de but stays de.domain.com/

    I hope my question is clear.

    Thanks in Advance,
    Matthijs

Viewing 3 replies - 1 through 3 (of 3 total)
  • You could route all subdomains to your wordpress directory – via the server settings in your hosting backend, not with some .htaccess directives.
    You then could detect a subdomain/language like this (though this might only work for oneWord.domain.tld and not more.than.one.word.domain.tld)

    $tmp        = explode( '.', $_SERVER['HTTP_HOST'] );
    
    $subdomain  = strtoupper(
      array_shift( $tmp )
    );
    
    switch( $subdomain ) {
    
      case 'DE':
        $lang = 'DE';
        break;
    
      case 'FR':
        $lang = 'FR';
        break;
    
      case 'NL':
        $lang = 'NL';
        break;
    
      default:
        $lang = 'EN';
        break;
    
    }
    
    if( !defined( 'LANGUAGE' ) ) {
    
      define( 'LANGUAGE', $lang );
    
    }

    This way you could check if( LANGUAGE == 'NL' )... whenever you need to.
    Depending on when that will be you might even put this code into your wp-config.php

    Thread Starter MatthijsdeGraaf

    (@matthijsdegraaf)

    Thank you very much for your response Chris – let me give that a try

    Thread Starter MatthijsdeGraaf

    (@matthijsdegraaf)

    That worked! Again, thank you very much Chris

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘language subdomain htaccess’ is closed to new replies.