We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28194
    • 5 Posts
    We have pages on our site that aren’t part of the CMS, and we’d like to leave them separate. But when you try to access them, ModX routes you to the default error page, based on either "OnPageNotFound" or "OnPageUnauthorized".

    I tried writing a plugin to deal with this, and have gotten most of the way. But I’m not sure how to allow access to the page once I tap into the system event. Both "sendRedirect" and "sendForward" don’t seem to be the right methods (see line "DO SOMETHING HERE" below).

    Is there an easier way to allow a passthrough for certain pages? We have SEO names turned on, if it matters.

    Thanks for any tips,

    John


    // ------------------
    $e = &$modx->Event;
    switch ($e->name)
    {
    case "OnPageNotFound":
    if(!$pg)
    {
    $target_url = $_SERVER["REQUEST_URI"];
    if ($target_url == "/stats")
    {
    // DO SOMETHING HERE.
    // $modx->sendRedirect($target_url);
    }
    else
    {
    $modx->sendErrorPage();
    }
    exit;
    }
    else
    {

    }
    break;

    default :
    return; // stop here
    break;
    }
    //------------------------
      • 7231
      • 4,205 Posts
      But when you try to access them, ModX routes you to the default error page
      This should not happen. In several cases I will have html files along side the modx (root level) and they continue to work. I would check your setup, maybe something in the htaccess file.
        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

        Something is happening here, but you don't know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 3749
        • 24,544 Posts
        If you provide a full URL link to those pages and they are outside the MODx site (so the MODx .htaccess won’t take effect), you should get straight to them.
          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
          • 28194
          • 5 Posts
          Thanks for the input. The files are inside the ModX domain and need to stay there. It’s good to know that it works for someone.

          The only active parts of the htaccess file are these lines:

          RewriteEngine On
          RewriteBase /

          # The Friendly URLs part
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

          Is there some other setup parameter that I should change?

          Thanks.

            • 3749
            • 24,544 Posts
            You could put an .htaccess file in the folder(s) holding the files with "rewrite engine off" in it if that wouldn’t cause you other problems. Otherwise, all URLS will end up as index.php?etc... and you won’t find your pages.

            I think you could also give the pages a prefix and add rewrite rules to the site .htaccess for that prefix.
              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
              • 18367
              • 834 Posts
              Why not just use a weblink?

              That way they will still be part of any menus (if you want) under the same domain but separate from the CMS.
                Content Creator and Copywriter
                • 28194
                • 5 Posts
                I’m probably not explaining it right, but here’s a shot...

                My domain controlled by ModX is something like:

                http://mydomain.com

                I have pages in the domain that aren’t entered into the ModX database. These are usually applications, like statistics trackers, product managers, etc. that we don’t want to rewrite in ModX. An example page location for one of these pages would be:

                http://mydomain.com/productmanager
                or
                http://mydomain.com/productmanager/somepage.php

                If I point to one of these pages with a web link -- either from a ModX page or from outside of ModX -- I get rerouted to the main "can’t find it" page set by ModX, which is:

                http://mydomain.com
                or
                http://mydomain.com/index.php?id=1

                Is there something in the htaccess file or in the ModRewrite setup used by ModX that is causing this?

                Thanks.
                  • 28194
                  • 5 Posts
                  Thanks for the tip -- I’ll try adding a different htaccess file to the subfolders.
                    • 18367
                    • 834 Posts
                    Spin,

                    all I can say is that I have separate pages that are not part of Modx, but are under my domain and in the same folder structure, and a weblink works fine.

                    I haven’t had to change the htaccess or anything else, so all I can say is it does work, for me at least.

                    My htaccess is the same as yours.

                    There must be something else going on.

                    What does it say for the url in the actual weblink in Modx?
                      Content Creator and Copywriter
                      • 28194
                      • 5 Posts
                      It looks like the problem is that you can’t use the htaccess file to password protect a folder in a domain that’s managed by ModX. At least not the way I was doing it.

                      I was trying to access a folder that contained the following htaccess file:

                      AuthType Basic
                      AuthUserFile /sompath/somefolder/.htpasswd
                      AuthName "SomeName"
                      require valid-user

                      I guess ModX couldn’t access the folder and suppresses the authentication dialog that usually appears when you protect a folder. I’ll figure out another way to protect the folder, but in the meantime, at least I can access files in unprotected folders.

                      Thanks for all of the tips. This was my first post on a ModX forum, and I’m impressed at how responsive everyone was. Much appreciated.