We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18366
    • 14 Posts
    I’ve run into severe problems trying to implement something simple and common place and would like to hear from others who have encountered this kind of issue and have work arounds. Thanks:

    Say I have a simple downloads page and on that it has links to various kind of files, say things like pdf documents and binary files, which I would like the user to be able to download by just clicking or right clicking and doing save as etc.

    I have of course created a basic page resource with alias ’downloads’ contained in the top level of my site tree. Friendly url aliases and alias paths are switched on. I’m also not using any prefixes or suffixes, so to access the page the user just types ....com/downloads in their browser.

    If I then create a physical directory in the installation webroot called downloads and put all the files I want to list in there, I run into the first major problem - Apache serves the raw directory instead of allowing Modx to process the url request. That means that the user gets shown a horrible directory listing. Of course I can disable the listing with the right .htaccess line but still I want Modx to process that url request so that I can show a nice page with a template consistent with the rest of the site and perhaps somekind of snippet to nicely show links to all my files contained in my downloads directory in whatever form that suits.

    Users can successfully access urls to download directly .....com/downloads/somefile and instantly download the file I want to give to them, but if they access the ’top level’ downloads page it’s not possible. Apache will try to serve the physical directory.

    If I don’t put my file resources in a physical downloads directory off the installation webroot, then where else can I put them? I could put them in the installation webroot (not a very nice place to store things!) or some other directory, but then the browser status bar url display will not make sense relative to the ....com/downloads address bar display.

    I’m starting to think that this is an impossible situation to solve in Modx itself, unless the files can go into the Modx database. I think perhaps it can be solved by apache configuration? I’m able to tell Apache to ignore the directory request but then I’m not sure how to get that request to be handled by Modx as it will just treat all accesses to ...com/downloads as an invalid resource id request.



      • 6228
      • 249 Posts
      Why not try to put an index.htm page in your downloads directory that has a meta-refresh straight to your MODx downloads resource id? e.g.

      <meta http-equiv="refresh" content="0;URL=http://www.mysite.com/index.php?13" />
        lo9on.com

        MODx Evolution/Revolution | Remote Desktop Training | Development
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        Your problem is that you are confusing the server. You have a resource with the alias "downloads", and you also have a directory "downloads". So if a request comes in for "domain.com/downloads", which one is the server supposed to serve?

        For proper security, the web server should be configured to not display a list of files like that anyway.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 18366
          • 14 Posts
          Thanks for your advice.

          I looked at various solutions and in the end what I did was a put a .htaccess in my physical downloads directory to deny a listing display in the browser, create an index.html resource in a Modx container resource with alias name ’downloads’ and then have my site root .htaccess have another rewrite rule to direct requests to ..../downloads to ..../downloads/index.html.

          This works exactly as I want and my index.html page is free to selectively show only what’s needed to be shown from the downloads directory, which is not everything.

          Perhaps the Modx team may want to look at having another resource type where the user can elect to have a resource that creates a blob in the database holding any kind of file. I’m not sure if that’s a good idea, I don’t know much about content management system design.