We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18913
    • 654 Posts
    I’m trying to use a .htaccess file that looks like this :
    <FilesMatch "\.(php|tpl)$">
       Order allow,deny
       Deny from all
    </FilesMatch>

    ... the idea being that I don’t want .php or .tpl files to be accessible from the browser.

    But when I test this on an example .php file, I get a "Firefox detects this page redirecting in a way that will never resolve" or something like that. Now, I know what that means, but I can’t get it to just redirect to the main page - essentially, to fail silently.

    The site’s main .htaccess is the default .htaccess, with the addition of Options -Indexes and a setting to properly recognize the subfolder in which the test install lives.

    I’m sure the answer is relatively simple, but I can’t seem to figure it out. Anyone with advice? Sorry for the bandwidth if I’m overlooking something very simple.

    Thanks,
    Matt

    PS This is Evo 1.0.4, Apache
      • 9207 ☆ A M B ☆
      • 2,475 Posts
      You can’t deny requests to PHP files on a MODx site... the index.php file would never be able to load, and any other request that got routed through Apache would get denied (e.g. file_get_contents() )... possibly include statements too (???).

      A better solution for this type of problem is to move your assets into a folder that’s ABOVE your site’s document root so there’s no way a browser can see them, e.g.

      /mysite
         /html/index.php <-- MODx stuff here
         /lib/  <-- My PHP stuff here
         /tpls/ <-- tpls here
      

      etc.

      Then adjust your paths in your scripts.
        • 18913
        • 654 Posts
        I should have clarified that the .htaccess file in question lives under the assets folder. Your point is well taken however. Have you managed to come up with a strategy that relocates an Evo install above the root? If so, I’d be interested in hearing about your approach.
        MattC
          • 9207 ☆ A M B ☆
          • 2,475 Posts
          It can be done, but it’s not simple... you’d have to point the includes in the index.php and the /manager/index.php to look above the root, and I’d guess you’d have all sorts of headaches to track down what got broken.

          Why not deny all EXTERNAL requests to those directories? This is how you deny hotlinking images, for example. Only allow requests from your own web server for anything in your assets folders. That would be more effective, I would think.