We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14349
    • 44 Posts
    Greetings.

    I have successfully gotten the manager managing 3 different websites (by creating 3 site context and by a simple Context Switch plugin ->
    <?php
    switch ($modx->getOption('http_host')) {
    
        case 'expotechnik-design.com':
            $modx->switchContext('expotechnik-designcom');
            break;
        
        case 'www.expotechnik-design.com':
            $modx->switchContext('expotechnik-designcom');
            break;
        
    
        case 'expotechnik-program.com':
            $modx->switchContext('expotechnik-programcom');
            break;
        
         case 'www.expotechnik-program.com':
            $modx->switchContext('expotechnik-programcom');
            break;
    
        case 'expotechnik-green.com':
            $modx->switchContext('expotechnik-greencom');
            break;
        
        case 'www.expotechnik-green.com':
            $modx->switchContext('expotechnik-greencom');
            break;
    
        default:
            $modx->switchContext('expotechnik-designcom');
            break;
    }


    My questions is how can I go about using friendly URLS with these multisites? Did some Htaccess work but to no avail. Also I made sure to give each context a friendly_urls setting to true as well as the entire site setting for friendlies to true

    Tried some variations of the following in my .htaccess (without the comments of course)

    #RewriteCond %{HTTP_HOST} .
    #RewriteCond %{HTTP_HOST} !^expotechnik-design\.com [NC]
    #RewriteRule (.*) http://expotechnik-design.com/$1 [R=301,L]
    
    #RewriteCond %{HTTP_HOST} .
    #RewriteCond %{HTTP_HOST} !^expotechnik-programs\.com [NC]
    #RewriteRule (.*) http://expotechnik-programs.com/$1 [R=301,L]
    
    #RewriteCond %{HTTP_HOST} .
    #RewriteCond %{HTTP_HOST} !^expotechnik-green\.com [NC]
    #RewriteRule (.*) http://expotechnik-green.com/$1 [R=301,L]


    I know the secret must be in mod_rewrite and something i’m doing in the .httaccess file.



    Edit:
    We solved this issue by editing the HTACCESS file like so -
    RewriteEngine On
    RewriteBase /
    # The Friendly URLs part
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]


    The key was keeping the main domain rewrite commented out (it was forcing back to the original domain)

    Then after giving each context it’s own settings (like start_page, Url, etc.) we set the main settings friendly_url on and the plugin above did the rest
      • 27672
      • 168 Posts
      could you use this same logic to work with subdomains? something like:
      <?php
      switch ($modx->getOption('http_host')) {
      
          case 'demo.domain.com':
              $modx->switchContext('demo');
              break;
          
          case 'www.domain.com':
              $modx->switchContext('web');
              break;
      
          case 'domain.com':
              $modx->switchContext('web');
              break;
      }

      ??