We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 813 ☆ A M B ☆
    • 326 Posts
    I think this is a fairly simple problem to solve, but I can’t quite get it.

    I work for a large university, and due to certain security settings on the servers, all code-executing php files have to be housed within a cgi-bin directory. So, I installed MODx in that directory, like so:

    http://www.example.com/cgi-bin/allmodxstuff

    I already have friendly URLs working. However, I’d also like to remove the /cgi-bin/ directory completely from the URL using mod_rewrite, so that if someone goes to http://www.example.com/page1, it will display the same as http://www.example.com/cgi-bin/page1.

    Can anyone tell me if this is possible, since the root of my MODx install is actually inside the cgi-bin subdirectory? If so, what does the code look like? Also, I don’t know if it matters, but we can’t run FollowSymlinks, so I have to have that line commented out.

    Thanks!
      • 5689
      • 289 Posts
      Is there anything else that needs to be accessible outside cgi-bin? For example, is there something like a www.example.com/index.html that you still need to be able to get to, or is everything on the whole website through the MODx installation in cgi-bin?

      At the most basic level, your .htaccess file would look something like this:

      Options -Indexes
      
      RewriteEngine On
      
      RewriteRule ^(.*)$ cgi-bin/$1 [L]


      Then, to avoid an infinite redirect loop, you’ll need to enable the .htaccess file in the MODx folder, which it sounds like you already did.

      Give that a try, and let me know how it works out. laugh
        I'm learning more about MODx all the time and loving it.
        • 813 ☆ A M B ☆
        • 326 Posts
        Thanks for your help, but that didn’t seem to work. I should clarify one thing, though, because I don’t think my original explanation was accurate. The sites are hosted on a www2 server where every sub-site has a unique username ("~awesomesite" in the example below), so the real domain is a little different from the domain people see. For example:

        A visitor types in www.awesomesite.example.com
        This takes them to what is actually hosted at www2.example.com/~awesomesite
        So, technically, my MODx install is hosted in the www2.example.com/~awesomesite/cgi-bin/ directory, not in www.example.com/cgi-bin as I originally said.

        Does this make sense? Does it change what will work for me here? Also, is it possible that I can’t use any of the "Options" in my .htaccess, since I can’t use FollowSymlinks?
          • 5689
          • 289 Posts
          Sorry for taking so long to get back to you. I don’t think the "Options" will make a difference. I just have it in there for some extra security because it disallows access to directory trees (if there is no index.html or similar in a folder). I’ll leave it out for simplicity.

          mod_rewrite usually takes me a while to get right any time I need to do a certain something, but try this. It might not work, but hopefully it’ll give you something.

          RewriteEngine On
          RewriteBase /
          
          RewriteRule ^(.*)$ cgi-bin/$1 [L]


          Then make sure you have this in .htaccess file in cgi-bin (the one MODx creates as ht.access when you install it):

          RewriteBase /


          I set up something like you described on my website, and it works with that mod_rewrite code. Hopefully it’ll work for you.
            I'm learning more about MODx all the time and loving it.