We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21619
    • 3 Posts
    Hi,
    I have a hosting with several domain hosted.
    in my public_html directory I have directories:
    domain1.com
    domain2.com
    domain3.com

    In the .htaccess file located in public_html I have the following code:

    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{HTTP_HOST}    ^domain1\.com [OR]
    RewriteCond %{HTTP_HOST}    ^www\.domain1\.com
    RewriteCond %{REQUEST_URI} !/domain1\.com
    RewriteRule ^(.*)$  /domain1\.com/$1 [L]
    
    RewriteCond %{HTTP_HOST}    ^domain2\.com [OR]
    RewriteCond %{HTTP_HOST}    ^www\.domain2\.com
    RewriteCond %{REQUEST_URI} !/domain2\.com
    RewriteRule ^(.*)$  /domain2\.com/$1 [L]
    
    RewriteCond %{HTTP_HOST}    ^domain3\.com [OR]
    RewriteCond %{HTTP_HOST}    ^www\.domain3\.com
    RewriteCond %{REQUEST_URI} !/domain3\.com
    RewriteRule ^(.*)$  /domain3\.com/$1 [L]
    


    When user enter domain1.com the server execute logic in /domain1.com/
    All the domains are linked to the root directory because the provider does not support much addon domains. I use theese as parked.


    The problem is after ModX installed on domain1.com, all the links in site are pointed to http://domain1.com/domain1.com/pageXXXXX
    This is physical directory, but I preffer to use rewrite conditions in htaccess.


    Please help me to solve that problem. Maybe some variable might be adjusted.
    CMS Made Simple has an option during installation to set the target URL and when I set it to http://domain1.com everything works, but here I cannot find similar option.

    Apache 2.2.11 (Unix)
    PHP 5.2.9
    MySQL 5.0.81-community-log
    x86_64
    OS Linux
    ModX latest version downloaded today.

    Regards
      • 22303 MODX Staff
      • 10,725 Posts
      If you are using friendly URLs, you might also need to move the rewrite conditions and rewrite rules from MODx into the .htaccess in your root, adding the conditions for each domain, inserted before each set of the domain-specific conditions and rules, something like this perhaps:
      RewriteEngine On
      RewriteBase /
      
      RewriteCond %{HTTP_HOST}    ^domain1\.com [OR]
      RewriteCond %{HTTP_HOST}    ^www\.domain1\.com
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ /domain1\.com/index.php?q=$1 [L,QSA]
      
      RewriteCond %{HTTP_HOST}    ^domain1\.com [OR]
      RewriteCond %{HTTP_HOST}    ^www\.domain1\.com
      RewriteCond %{REQUEST_URI} !/domain1\.com
      RewriteRule ^(.*)$  /domain1\.com/$1 [R=301,L]
      
      RewriteCond %{HTTP_HOST}    ^domain2\.com [OR]
      RewriteCond %{HTTP_HOST}    ^www\.domain2\.com
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ /domain2\.com/index.php?q=$1 [L,QSA]
      
      RewriteCond %{HTTP_HOST}    ^domain2\.com [OR]
      RewriteCond %{HTTP_HOST}    ^www\.domain2\.com
      RewriteCond %{REQUEST_URI} !/domain2\.com
      RewriteRule ^(.*)$  /domain2\.com/$1 [R=301,L]
      
      RewriteCond %{HTTP_HOST}    ^domain3\.com [OR]
      RewriteCond %{HTTP_HOST}    ^www\.domain3\.com
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ /domain3\.com/index.php?q=$1 [L,QSA]
      
      RewriteCond %{HTTP_HOST}    ^domain3\.com [OR]
      RewriteCond %{HTTP_HOST}    ^www\.domain3\.com
      RewriteCond %{REQUEST_URI} !/domain3\.com
      RewriteRule ^(.*)$  /domain3\.com/$1 [R=301,L]
      
        • 21619
        • 3 Posts
        It is not necessary, .htaccess is working perfectly with frendly urls.
        The problem is that ModX knows that it is installed on folder different from www root (public_html).

        The aim of conditions in my .htaccess in www root folder is when a user types domain1.com/page1 to see a site placed in folder public_html/domain1.com. And everythig works perfectly, even I type domain1.com, ModX (which is installed on public_html/domain.com folder) can be viewed. But every link in site is pointed to domain1.com/domain1.com/pageXX. I need the links to point to domain1.com/pageXX.
        Because domain1.com is linked to public_html folder, folder domain1.com in public_html belongs to domain1.com. And ModX knows that. I need to tell ModX that construction of links must be in different way. I need to replace remembered location /domain1.com/ with /

        Thanks
          • 22303 MODX Staff
          • 10,725 Posts
          MODx creates links relative to the site root, so you simply need to set your base href to what the site_url should be. It might also be necessary to hardcode the site_url in the config file rather than letting MODx determine it from the $_SERVER variables which are normally set properly by the web server configuration. Since you have a non-standard configuration and are using rewrite rules to control access to your domains, these will not be correct.
            • 21619
            • 3 Posts
            I think I fix the problem.

            In /manager/includes/config.inc.php file I add
            $url = "/";
            in the following part of code:

            if(empty($base_path)||empty($base_url)||$_REQUEST['base_path']||$_REQUEST['base_url']) {
                $sapi= 'undefined';
                if (!strstr($_SERVER['PHP_SELF'], $_SERVER['SCRIPT_NAME']) && ($sapi= @ php_sapi_name()) == 'cgi') {
                    $script_name= $_SERVER['PHP_SELF'];
                } else {
                    $script_name= $_SERVER['SCRIPT_NAME'];
                }
                $a= explode("/manager", str_replace("\\", "/", dirname($script_name)));
                if (count($a) > 1)
                    array_pop($a);
                $url= implode("manager", $a);
                reset($a);
                $a= explode("manager", str_replace("\\", "/", dirname(__FILE__)));
                if (count($a) > 1)
                    array_pop($a);
                $pth= implode("manager", $a);
                unset ($a);
            
                $url = "/"; // This line is added to force main folder calls instead of real one!
            
                $base_url= $url . (substr($url, -1) != "/" ? "/" : "");
                $base_path= $pth . (substr($pth, -1) != "/" && substr($pth, -1) != "\\" ? "/" : "");
                // assign site_url
                $site_url= ((isset ($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') || $_SERVER['SERVER_PORT'] == $https_port) ? 'https://' : 'http://';
                $site_url .= $_SERVER['HTTP_HOST'];
                if ($_SERVER['SERVER_PORT'] != 80)
                    $site_url= str_replace(':' . $_SERVER['SERVER_PORT'], '', $site_url); // remove port from HTTP_HOST  
                $site_url .= ($_SERVER['SERVER_PORT'] == 80 || (isset ($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') || $_SERVER['SERVER_PORT'] == $https_port) ? '' : ':' . $_SERVER['SERVER_PORT'];
                $site_url .= $base_url;
            }



            Then clear the site cashe and everything is just fine. smiley
            It would be good ModX to provide this option during installation process. Many other CMS systems provide it.