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

    we have built a site for a client using modx (096) but we have just found out that they would like to have a version of the site on HTTPS (they have some customers that will access the site via an SSL application)

    i know that we can copy the system files from HTTP into HTTPS and have both sites share the same database and assets, that’s not a problem. the problem is that in modx configuration you can only set the site as HTTP or HTTPS, which means that the navigation of the site will always be one or the other regardless of which version of the site the user is viewing.

    the server type setting is held in the database so is there a way to manually set this in the config file of each version that will supercede the database value?

    is there any way around this? any ideas greatly appreciated!!

    thanks smiley
      • 22303 MODX Staff
      • 10,725 Posts
      That setting isn’t really used for anything.

      You can access any modx site from multiple domains; that’s up to how you have your domains mapped in your web server. However, you seem to indicate something about copying files which would tell me that you have separate directories serving HTTP and HTTPS on your web server. That will be more problematic, and I don’t see an easy way to deal with it.

      The only sites I have that are both SSL and non-SSL are served from the same directory and MODx takes care of forcing the pages that must be SSL (for PCI compliance) to https and the others to http using a custom plugin I wrote for it.
        • 12151
        • 115 Posts
        yes, that is exactly what we are currently trying to do and yes, it is proving problematic!

        any chance you can elucidate more on the solution you came up with to serve both versions from the same directory?

        thanks!
          • 21634
          • 1 Posts
          We too are having the same problem trying to get HTTP and HTTPS to work off one directory.

          Any help would be much appreciated!
            • 22303 MODX Staff
            • 10,725 Posts
            You could try something like this plugin to direct traffic between https and http. This is how I force a comma-delimited list of document ID’s to http or https. I’ve done this by specifying ID’s that are supposed to be "insecure", but you could also reverse the login so you could just specify the pages to be "secure". You may need to test and adjust this for your setup; and FYI, you specify the insecurePages variable in the plugin configuration. Register the plugin for OnWebPageInit.

            <?php
            /**
             * A MODx plugin to force requests to certain pages to an SSL version.
             */
            if ($modx->event->name == 'OnWebPageInit') {
                if (isset ($insecurePages)) {
                    $insecurePages= explode(',', $insecurePages);
                } else {
                    $insecurePages= array ();
                }
                
                if ($_SERVER['SERVER_PORT'] == 443 || (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS'])=='on')) {
                    if (in_array($modx->documentIdentifier, $insecurePages)) {
                        $modx->sendRedirect($modx->makeUrl($modx->documentIdentifier, '', '', 'http'));
                    }
                } else {
                    if (!in_array($modx->documentIdentifier, $insecurePages)) {
                        $modx->sendRedirect($modx->makeUrl($modx->documentIdentifier, '', '', 'https'));
                    }
                }
            }
            ?>
              • 12151
              • 115 Posts
              Hi Jason,

              Many thanks for this plugin. I see that this would work well for specific pages but in this case I need the entire site to be served as HTTP and HTTPS (I would have a version of all the modx system files in both directories).

              Would your plugin work if I ignored the $insecurePages and simply used the
              if ($_SERVER[’SERVER_PORT’] == 443 || (isset($_SERVER[’HTTPS’])) to determine which version was being requested in the URL?

              Or would the plugin need to be changed further?

              Many thanks!
                • 22303 MODX Staff
                • 10,725 Posts
                I don’t understand, if there is no redirection and all pages are available both secure and unsecure (which is by-the-way, insecure by definition), why do you need the plugin at all; wouldn’t it just serve which was requested? This plugin is designed for http and https to be delivered from the same directory and for pages to be exclusively available as one or the other, not both, forcing a redirect if a page is accessed with the wrong protocol.
                  • 12151
                  • 115 Posts
                  jason,

                  for reasons beyond my understanding the client of the site in question wants to have both HTTP and HTTPS versions of the same site. (i think this is due to some of their clients that will access the site via a desktop application that uses HTTPS). obviously they don’t want to duplicate every single page of the site, hence attempting to run off the same database.

                  if i duplicate just the modx system files into the https directory and use the http version of the manager to edit content both versions work immediately. however, the links within the site (the one’s created by wayfinder, ditto, etc) are all "http://" regardless of which URL is used. this is where i am having problems. once the user is viewing the https version i can’t get the links to remain as https, they always revert to http.

                  does this make any sense at all??

                  :)
                    • 25663 MODX Staff
                    • 12,272 Posts
                    Maybe create a symbolic link from the http directory and make it the https directory?
                      Ryan Thrash, MODX Co-Founder
                      Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                      • 12151
                      • 115 Posts
                      Quote from: rthrash at Oct 29, 2007, 11:52 AM

                      Maybe create a symbolic link from the http directory and make it the https directory?

                      sorry, i don’t understand. how would this work and how would i implement this?