[resolved] language subdomain htaccess (4 posts)

  1. MatthijsdeGraaf
    Posted 3 years ago #

    Hi all,

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

    http://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 http://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 http://www.domain.com/?lang=de but stays de.domain.com/

    I hope my question is clear.

    Thanks in Advance,

  2. Chris
    Posted 3 years ago #

    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';
      case 'FR':
        $lang = 'FR';
      case 'NL':
        $lang = 'NL';
        $lang = 'EN';
    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

  3. MatthijsdeGraaf
    Posted 3 years ago #

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

  4. MatthijsdeGraaf
    Posted 3 years ago #

    That worked! Again, thank you very much Chris

Topic Closed

This topic has been closed to new replies.

About this Topic