We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40088
    • 708 Posts
    Prior to using MODX when I created a subdomain I could access it at http://subdomain.site.com. But with MODX it redirects me to http://site.com/subdomain. Everything still works fine so this isn't really a problem. Still, I would like to know if there's a way to modify the MODX .htaccess file so the subdomain url looks like the first example above without of course breaking the MODX functionality.
      Todd
      • 44234
      • 219 Posts
      Have not seen this before, could you post your .htaccess?
        Find me on Twitter, GitHub or Google+
        • 40088
        • 708 Posts
        I'm using the default MODX .htaccess with one exception: a change to the rewrite was necessary (thanks BobRay) because it wasn't working with the A2 Hosting configuration.

        By the way, when I disable the .htaccess the subdomain url works as expected, http://subdomain.site.com.

        RewriteEngine On
        RewriteBase /
        
        # Rewrite www.domain.com -> domain.com -- used with SEO Strict URLs plugin
        # RewriteCond %{HTTP_HOST} .
        # RewriteCond %{HTTP_HOST} !^site\.com [NC]
        # RewriteRule (.*) http://site.com/$1 [R=301,L]
        
        # This rewrite is specific to the host because the one above did not work.
        RewriteCond %{HTTP_HOST} .
        RewriteCond %{HTTP_HOST} !^site\.com [NC]
        RewriteRule ^(.*)$ http://site.com/$1 [R=301,L]
          Todd
          • 44234
          • 219 Posts
          Try adjusting your .htaccess as below:
          RewriteEngine On
          RewriteBase /
          
          # Rewrite www.domain.com -> domain.com -- used with SEO Strict URLs plugin
          RewriteCond %{HTTP_HOST} ^site\.com [NC]
          RewriteRule ^(.*)$ http://site.com/$1 [R=301,L]
          
          # The Friendly URLs part - MUST BE SPECIFIC TO TOP-LEVEL HOST SO AS NOT TO CONFLICT WITH SUBFOLDER REDIRECTS
          RewriteCond %{HTTP_HOST} ^www\.site\.com
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA]
          

          Remember to keep the order the same as I have shown above
            Find me on Twitter, GitHub or Google+
            • 40088
            • 708 Posts
            Hi David,

            When I disabled the default settings and used your example it throws a “too many redirects” error.
              Todd
              • 3109 ☆ A M B ☆
              • 894 Posts
              What method are you using to host multiple sites? Are you doing it manually or are you using ContextRouter.

              If you use ContextRouter you don't have to edit the htaccess or anything else besides creating some Context Settings.

              I go through this in my ContextRouter Review on my blog.

              Good Luck.
                Benjamin Marte
                Interactive Media Developer
                Follow Me on Twitter | Visit my site | Learn MODX
                • 40088
                • 708 Posts
                Quote from: benmarte at Feb 20, 2014, 04:43 PM
                What method are you using to host multiple sites?

                Hi benmarte,

                For this particular site I'm not hosting multiple sites, just the one.

                I'm trying to understand what it is about my htaccess file that prevents me from viewing my subdomain url at http://subdomain.mysite.com instead of redirecting to http://mysite.com/subdomain. I was hoping David's suggestion above would work but unfortunately it didn't.

                It's probably something simple that I'm not seeing. If anyone else uses A2 Hosting with MODX I would be interested to hear how your subdomain url's work/look.
                  Todd
                  • 36816
                  • 109 Posts
                  Greetings todd.b,

                  I've run across this myself, although with a different host (Bluehost).

                  I believe that the culprit is the following RewriteCond, which is saying, as I read it, "If the host name does not start with 'site.com'" execute the RewriteRule that follows. In more typical use, this would redirect www.site.com -> site.com.

                  RewriteCond %{HTTP_HOST} !^site\.com [NC]


                  Because your host name when you access via subdomain indeed does not start with "site.com" (it starts with "subdomain.site.com", it's processing the redirect, which you don't want in the case of accesses to your subdomain.

                  In my use case where I've encountered this, I had site.com set to redirect to www.site.com, so my solution wouldn't work for you, as you're doing the reverse, but the following RewriteCond may do the trick for you. I've not tested it, so your mileage may vary.

                  RewriteCond %{HTTP_HOST} !^(subdomain\.site|site)\.com [NC]


                  The alternate RewriteCond is saying, "if the host name does not start with subdomain.site.com or just plain site.com, perform the redirect". In theory, this may let you skip that redirect and just go to your subdomain. In the case of accesses via "www.site.com" (or "bla.site.com" for that matter) the redirect should still happen.

                  As to the wisdom of the host processing the .htaccess in the "main" domain's root when accessing a subdomain, that's another story.
                    • 40088
                    • 708 Posts
                    clareoconsulting, thanks for the very clear explanation.

                    Your suggestion did indeed get me a step closer, though while it works great on the homepage when I start navigating through the site it throws a 500 error.
                      Todd
                      • 36816
                      • 109 Posts
                      To check - you're saying that the http 500 errors are coming when you're navigating to http://site.com/my-friendly-url, not when accessing the http://subdomain.site.com subdomain?

                      If so, I'm puzzled, as the change to that particular RewriteCond should be ignored when on the "main" site.

                      To double-check, I was proposing that you change the RewriteCond in line 11 of reply #3 in this thread. There should also be other RewriteCond lines to handle the friendly URLs business; I didn't mean to change anything about those.

                      It feels like I'm missing something; Monday-AM syndrome is clearly at work.