WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] language subdomain htaccess (4 posts)

  1. MatthijsdeGraaf
    Member
    Posted 1 year 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,
    Matthijs

  2. Chris
    Member
    Posted 1 year 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';
        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

  3. MatthijsdeGraaf
    Member
    Posted 1 year ago #

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

  4. MatthijsdeGraaf
    Member
    Posted 1 year ago #

    That worked! Again, thank you very much Chris

Topic Closed

This topic has been closed to new replies.

About this Topic