We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 51481
    • 45 Posts
    My domain is http://comox.ca and my current site is not loading any CSS, JS, or images. I originally installed MODX to a subfolder (/modx/) and have
    RewriteEngine On
    RewriteBase /modx/

    in my .htaccess file which is in public_html/modx.

    Everything was working fine, and then I had to change my DNS records. I have (in the A records)
    comox.ca -> 67.231.17.10
    www.comox.ca -> 67.231.17.10

    which is pointing to the ip address given to me by my host (and what I was using for months for development) and seems to be working fine.

    When I view my page source, all of the paths to CSS, JS, and image files have /modx/ in them because that's where they are stored on the server... For example,
    <script src="/modx/assets/js/picturefill.js" async></script>

    However, when I click on that link I get a 500 server error... But when I remove "modx/" it pulls up the correct file or image. Also, going to comox.ca/modx/assets gives a 500 server error, while comox.ca/assets brings up my asset tree. Even though the path to my assets folder is /home/username/public_html/modx/assets.

    I did have an .htaccess file in my public_html folder that had
    RedirectMatch ^/$ /modx/

    So that when people typed comox.ca they would be brought to comox.ca/modx and the site would show... But that was before the DNS change so I have commented it out for now.

    What is going on?!

    EDIT: I should mention that I am also unable to re-run the setup script... I put setup.zip in my public_html/modx folder, unzip it, and go to comox.ca/modx/setup which gives me a 404 and comox.ca/setup which gives me a 500 error.

    EDIT: I will also include my core/config/config.inc.php paths:
    if (!defined('MODX_CORE_PATH')) {
        $modx_core_path= '/home/townofco/core/';
        define('MODX_CORE_PATH', $modx_core_path);
    }
    if (!defined('MODX_PROCESSORS_PATH')) {
        $modx_processors_path= '/home/townofco/core/model/modx/processors/';
        define('MODX_PROCESSORS_PATH', $modx_processors_path);
    }
    if (!defined('MODX_CONNECTORS_PATH')) {
        $modx_connectors_path= '/home/townofco/public_html/modx/connectors/';
        $modx_connectors_url= '/modx/connectors/';
        define('MODX_CONNECTORS_PATH', $modx_connectors_path);
        define('MODX_CONNECTORS_URL', $modx_connectors_url);
    }
    if (!defined('MODX_MANAGER_PATH')) {
        $modx_manager_path= '/home/townofco/public_html/modx/manager/';
        $modx_manager_url= '/modx/manager/';
        define('MODX_MANAGER_PATH', $modx_manager_path);
        define('MODX_MANAGER_URL', $modx_manager_url);
    }
    if (!defined('MODX_BASE_PATH')) {
        $modx_base_path= '/home/townofco/public_html/modx/';
        $modx_base_url= '/modx/';
        define('MODX_BASE_PATH', $modx_base_path);
        define('MODX_BASE_URL', $modx_base_url);
    }
    if(defined('PHP_SAPI') && (PHP_SAPI == "cli" || PHP_SAPI == "embed")) {
        $isSecureRequest = false;
    } else {
        $isSecureRequest = ((isset ($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') || $_SERVER['SERVER_PORT'] == $https_port);
    }
    if (!defined('MODX_URL_SCHEME')) {
        $url_scheme=  $isSecureRequest ? 'https://' : 'http://';
        define('MODX_URL_SCHEME', $url_scheme);
    }
    if (!defined('MODX_HTTP_HOST')) {
        if(defined('PHP_SAPI') && (PHP_SAPI == "cli" || PHP_SAPI == "embed")) {
            $http_host='comox.ca';
            define('MODX_HTTP_HOST', $http_host);
        } else {
            $http_host= array_key_exists('HTTP_HOST', $_SERVER) ? $_SERVER['HTTP_HOST'] : 'comox.ca';
            if ($_SERVER['SERVER_PORT'] != 80) {
                $http_host= str_replace(':' . $_SERVER['SERVER_PORT'], '', $http_host); // remove port from HTTP_HOST
            }
            $http_host .= ($_SERVER['SERVER_PORT'] == 80 || $isSecureRequest) ? '' : ':' . $_SERVER['SERVER_PORT'];
            define('MODX_HTTP_HOST', $http_host);
        }
    }
    if (!defined('MODX_SITE_URL')) {
        $site_url= $url_scheme . $http_host . MODX_BASE_URL;
        define('MODX_SITE_URL', $site_url);
    }
    if (!defined('MODX_ASSETS_PATH')) {
        $modx_assets_path= '/home/townofco/public_html/modx/assets/';
        $modx_assets_url= '/modx/assets/';
        define('MODX_ASSETS_PATH', $modx_assets_path);
        define('MODX_ASSETS_URL', $modx_assets_url);
    }
    [ed. note: matthewmeredith last edited this post 10 years, 3 months ago.]
      • 3749
      • 24,544 Posts
      I'm not sure I'm following you completely, but on most hosts, the RewriteBase in .htaccess should be a single slash, even if the site is in a subdirectory as long as the IP or URL is set to direct to that subdirectory.

      Make sure you have this in the head section of all your templates:

      <base href="[[!++site_url]]" />


      If you only have one front-end context, you can remove the !, but I recommend having it there until everything is working.

      Just changing the RewriteBase might be enough if the links to your CSS and JS files use MODX tags rather than being hard-coded. [ed. note: BobRay last edited this post 10 years, 3 months ago.]
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 51481
        • 45 Posts
        Quote from: BobRay at Jun 21, 2016, 12:45 PM
        I'm not sure I'm following you completely, but on most hosts, the RewriteBase in .htaccess should be a single slash, even if the site is in a subdirectory as long as the IP or URL is set to direct to that subdirectory.

        Make sure you have this in the head section of all your templates:

        <base href="[[!++site_url]]">


        If you only have one front-end context, you can remove the !, but I recommend having it there until everything is working.

        Just changing the RewriteBase might be enough if the links to your CSS and JS files use MODX tags rather than being hard-coded.

        Thanks for the suggestions, Bob! Yes, I have <base href="http://comox.ca/modx/" /> in the head section (I can't get into the manager right now but I know for sure that it was [[!+site_url]]). I changed my RewriteBase to "/modx" (without quotes) but no change.

        Sorry, I explained it rather poorly. Basically, if I navigate to http://comox.ca/assets/images/logos/ComoxCaptivates_blue_220.png it brings up the file, EVEN THOUGH the file is actually located at /home/townofco/public_html/modx/assets/images/logos/ComoxCaptivates_blue_220.png.

        When I navigate to comox.ca, I shouldn't even see the website! I should see

        cgi-bin/
        modx/
        info.php

        and then clicking on modx/ should bring me to the site (at least that's the way it used to work). [ed. note: matthewmeredith last edited this post 10 years, 3 months ago.]
          • 3749
          • 24,544 Posts
          I was suggesting this in .htaccess:

          RewriteBase /


          and removing modx anywhere else it appears in active rules in .htaccess, and in *just* the URLs in the config.inc.php file (not the paths).

          Based on what you've said, your site is actually *located* at comox.ca now, in spite of the fact that it's in a subdirectory. I think the only reason that you still see the '/modx' in the source is the old RewriteBase in .htaccess.

          MODX creates the site_url value based on the URL you come in on. If the RewriteBase has 'modx/' in it, that will become part of the site_url even though it's no longer needed. That's why your CSS and JS aren't being found and any links don't work.

          If my theory is right, you no longer need 'modx/' in any URLs or in the .htaccess file. The only time you'll need it is when you need to refer to a *path* rather than a URL -- as in the config.core.php files, the paths in config.inc.php, and any PHP 'include' statements (which should use MODX_CORE_PATH or MODX_ASSETS_PATH anyway).


          BTW, if you make just the change above to .htaccess, you may be able to run Setup and it may well straighten out everything else. Don't proceed unless Setup is in 'Upgrade' mode.

          Another thought: You really don't want modx in your site URL. It gives would-be hackers a leg up.

          If there are existing links to the site, it's easy enough to add a rewrite rule in .htaccess that will send them to the proper location at comox.ca.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 51481
            • 45 Posts
            Quote from: BobRay at Jun 21, 2016, 04:51 PM
            I was suggesting this in .htaccess:

            RewriteBase /


            and removing modx anywhere else it appears in active rules in .htaccess, and in *just* the URLs in the config.inc.php file (not the paths).

            Based on what you've said, your site is actually *located* at comox.ca now, in spite of the fact that it's in a subdirectory. I think the only reason that you still see the '/modx' in the source is the old RewriteBase in .htaccess.

            MODX creates the site_url value based on the URL you come in on. If the RewriteBase has 'modx/' in it, that will become part of the site_url even though it's no longer needed. That's why your CSS and JS aren't being found and any links don't work.

            If my theory is right, you no longer need 'modx/' in any URLs or in the .htaccess file. The only time you'll need it is when you need to refer to a *path* rather than a URL -- as in the config.core.php files, the paths in config.inc.php, and any PHP 'include' statements (which should use MODX_CORE_PATH or MODX_ASSETS_PATH anyway).


            BTW, if you make just the change above to .htaccess, you may be able to run Setup and it may well straighten out everything else. Don't proceed unless Setup is in 'Upgrade' mode.

            Another thought: You really don't want modx in your site URL. It gives would-be hackers a leg up.

            If there are existing links to the site, it's easy enough to add a rewrite rule in .htaccess that will send them to the proper location at comox.ca.

            Bob, thanks again for all that info! Yes I agree, I don't want modx in the urls... I left this issue with my hosting provider and they sorted it out, but I would still like to remove modx from urls.

            So just to make sure I'm understanding you, I only need to edit my core/config/config.inc.php file and the .htaccess file found in public_html/modx? I have an .htaccess file in public_html right now that just has:
            RewriteCond %{HTTP_HOST} ^(www\.)?comox\.ca$ [NC]
            RewriteRule !^modx/ /modx%{REQUEST_URI} [L,NC]

            to remove "modx" from URLs, although it's only doing it for the home page.

            So, I should:
            1. Remove the .htaccess file in my web root
            2. Change the .htaccess file in public_html/modx to be "RewriteBase /" instead of "RewriteBase /modx"
            3. Make sure my paths in config.inc.php still have modx in them

            Edit: I just looked at the e-mail from my hosting provider on their solution and they said the following:
            "There was a conflict between the document root path and the modx installation path
            mentioned in your config file. We have corrected the document root path of your site and that resolved the issue"

            So, I probably shouldn't do that... Because the website is back to using comox.ca/modx and is working properly. Shoot!

            Is there another way I can hide the modx/ in the URLs? I have the homepage fixed, but all subpages still have it.
              • 3749
              • 24,544 Posts
              You can create a plugin to show a custom URL, but it complicates things and slows down page loads by a trivial amount. If it were me, I'd either perform the steps above and have the host change the document root back to comox.ca (it makes for a much more straightforward setup)

              or

              If it's the only site there, you could also just move everything up one level to the web root and adjust the config files accordingly. That's actually the simplest setup. In that case, you'd want the document root where it was before they "fixed" it (at comox.ca), and .htaccess with RewriteBase / in that same root. You'd need to fix the config.inc.php file and the three config.core.php files (just one line) in the MODX root, manager, and connectors directories. Then you wouldn't need to use "modx/" anywhere at all -- much less chance of confusion and error.

              I can see, though, why you wouldn't want to mess with a working site.
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting