We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17895
    • 209 Posts
    I have two directory in my root, one contains modx and one another site (that is also a subdomain)... how can this work with frendly urls?

    Everything works fine in the modx subdirectory, but how can I redirect ONLY the url that start with /myOtherSite/ on that subdir?

    i.e., i want this

    www.mysite.com/foo.html -> www.mysite.com/modx/foo.html
    www.mysite.com/theOtherSite/bar.html -> www.mysite.com/theOtherSite/bar.html
    theOtherSite.mysite.com/bar.html -> www.mysite.com/theOtherSite/bar.html (this worked if i do not change the .htaccess of the root directory)
      Daniele "MadMage" Calisi
      • 22303 MODX Staff
      • 10,725 Posts
      @madmage: you should be able to simply put the rewrite rules into an htaccess in the /modx subdirectory -- that will then only be engaged if the request begins with /modx/ -- just remember to modify the rule to include the subdirectory path as indicated in the included ht.access
        • 17895
        • 209 Posts
        Quote from: OpenGeek at Jul 09, 2006, 02:20 PM

        @madmage: you should be able to simply put the rewrite rules into an htaccess in the /modx subdirectory -- that will then only be engaged if the request begins with /modx/ -- just remember to modify the rule to include the subdirectory path as indicated in the included ht.access

        but the request WILL NOT begin with /modx/ as you can see in my examples
          Daniele "MadMage" Calisi
          • 30223
          • 1,010 Posts
          Assuming that both www.mysite.com and www.theOtherSite.com are pointing to the same directory (documentRoot) adn also assuming you only have a MODx CMS installed on www.mysite.com (and not on www.theOtehrSite.com) you can try this in your .htaccess file

          RewriteEngine On
          #make sure we have a HTTP_HOST request header
          RewriteCond %{HTTP_HOST}  !^$
          #only redirect requests for www.mysite.com
          RewriteCond %{HTTP_HOST} ^www\.mysite\.com$ [NC]
          #and if not in the modx directory
          RewriteCond %{REQUEST_FILENAME} !/modx/.*$ [NC]
          #and not in the theOtherSite directory
          RewriteCond %{REQUEST_FILENAME} !/theOtherSite/.*$ [NC]
          #from original modx rewrite
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteCond %{REQUEST_FILENAME} !-d
          #only then redirect to modx index page
          RewriteRule ^([^/].*) modx/index.php?q=$1 [L,QSA]
          
          
          #assuming there's no modx cms on www.theOtherSite.com
          RewriteCond %{HTTP_HOST}  !^$
          RewriteCond %{HTTP_HOST} ^www\.theOtherSite\.com$ [NC]
          #if not already in the theOtherSite directory
          RewriteCond %{REQUEST_FILENAME} !/theOtherSite/.*$ [NC]
          #only then redirect to theOtherSite directory
          RewriteRule ^([^/].*) theOtherSite/$1
          


          I tried this out on my local server and it works with one (or rather two) exceptions. If you go to www.mysite.com/ or www.theOtherSIte.com/ (ie without a filename) the redirection will not happen and the server will try to find index.html (or whatever your index file is) in the document root. I couldn’t find a way around it with rewrite. You could solve this with an index.php file in the document root which test what domain is requested and redirect to the correct directory...

          <?php
          if( $_SERVER['HTTP_HOST'] == 'www.theOtherSite.com' )
              header("location: /theOtherSite/index.php");
          else
              header("location: /modx/index.php");
          ?>
          
            • 17895
            • 209 Posts
            thanks a lot, TobyL... the problem with your solution is that index.php points to /modx/index.php, but I want to hide that directory to the world (this is one of the reasons I wanna use mod_rewrite)

            but if I write /index.php, the browser stops for infinite redirections
              Daniele "MadMage" Calisi
              • 22303 MODX Staff
              • 10,725 Posts
              I don’t understand the problem here. Madmage, what are you trying to accomplish? If you don’t want /modx in your URL, simply move the modx index.php and all modx subfolders to the root level. Why did you install modx under /modx if you want /modx not to show in the URL’s?
                • 17895
                • 209 Posts
                Jason: yes, that’s the simple way smiley
                Anyway, I know that mod_rewrite is usually used in this way to add a level of security to the website...
                It’s not necessary, but I would like to know how to make it work... ;-)
                  Daniele "MadMage" Calisi