We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10702
    • 107 Posts
    We want to protect a single website by a password. Before we moved to MODx we did this by .htaccess giving a single folder a password.

    Does anybody know how we can manage this in MODx Revolution in an easy way?

    Thanks a lot in advance! smiley
    Gerdi
      • 3749
      • 24,544 Posts
      One way is to put a snippet tag in all your templates with this in the snippet code:

      <?php
      $isAuthenticated = $modx->user->hasSessionContext($modx->context->get('key'));
      if (!$isAuthenticated) {
      $modx->sendUnauthorizedPage();
      }
      

      That will forward everyone who is not logged in to the unauthorized page.

      Then define an unauthorized page in System Settings and put the Login snippet on that page.

      Adding &redirectToPrior=`1` to the login snippet tag will send the user to the page they were trying to reach after they log in.
        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