We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13643
    • 44 Posts
    I spent most of the day yesterday following the instructions in this article to set up a context on a subdomain. The only step I was not able to complete as written was setting up the virtual host. Since I’m on shared hosting (HostGator) I used the subdomain utility in cPanel, which, I believe accomplishes the same thing (someone please correct me if I’m wrong on this).

    The only thing that works about this so far is that subdomain.domain.com brings up the "site_start" page for the subdomain context. That page uses the default template from the main context, which references resources in the "assets" directory. The trouble here is that all these references from the default template (CSS files, etc.) are re-written with the base URL of the subdomain, and are thus not found. Is this the way it’s supposed to work? Or is there some way to link to the same resources from the subdomain context without duplicating the template?

    The larger problem I have is that the other pages in the subdomain context will not come up at all, whether accessed through the "View" link from the Manager, or directly by name or resource number. Instead, I get the error page from the main domain context (not even the error page specified in the subdomain context). It’s almost as if the system doesn’t recognize that these page are supposed to be in the subdomain context at all.

    Any suggestions?
      • 22303 MODX Staff
      • 10,725 Posts
      Quote from: javadecaf at Jun 21, 2011, 10:03 AM

      I spent most of the day yesterday following the instructions in this article to set up a context on a subdomain. The only step I was not able to complete as written was setting up the virtual host. Since I’m on shared hosting (HostGator) I used the subdomain utility in cPanel, which, I believe accomplishes the same thing (someone please correct me if I’m wrong on this).
      You cannot control virtual host configurations on most shared hosts. I believe the cPanel utility uses mod_rewrite to handle requests to subdomains configured through that utility, which is very different from configuring Apache to handle the routing via a virtual host configuration. Unfortunately, I do not have access to test this type of setup with a subdomain Context at the moment, but there may be others here who have gotten this to work.
        • 13643
        • 44 Posts
        I’ guess I’m not too surprised to learn that there’s a difference in the way this works on the back-end. What I really need to know, though, is if the end result should be the same, or if the way HG does the subdomain is what’s causing the problem. I came across this tutorial yesterday as well, where the author used mod_rewrite, and it seemed to work for him, so if that’s what HG is using on the back-end, seems like we should be OK, right?
          • 9102 ☆ A M B ☆
          • 318 Posts
          I have subdomains working under cpanel, using cpanel to configure the subdomain to point to a subfolder. I’m using the same setup as the article you mentioned -- separate index.php in the subdomain folder which initiates the subdomain context. The main things I would double-check are that all of your context settings have been modified correctly, and that .htaccess in the subdomain folder is correct. It sounds like the mod_rewrite configuration is correct, otherwise you wouldn’t be able to see the site start. I bet there’s an internal MODx setting that needs to be changed.

          As for the template problem, I think you’re probably going to want to have a separate template for the subdomain. You could copy your assets directory to the subfolder but then you have to maintain it in two places -- probably better to just make a new template and use absolute URLs to reference resources from the main domain.
            • 13643
            • 44 Posts
            Thanks for the input, Eli. When you visit yoursubdomain.yourdomain.com, does your browser display the URL as yourdomain.com/yoursubdomain? That’s what mine is doing, presumably because of the way HG handles the rewrite, and I’m suspicious that might have something to do with the problem.

            I double-checked my context settings as you suggested. Other than the settings specified in the tutorial, which mine parallel exactly, the only other one I’ve overridden is the error page (with no apparent effect, as I mentioned earlier). The site is in development, so I suppose it’s possible there’s a site-wide setting that needs to be overridden and isn’t, but I don’t know what it would be.

            Regarding the templates, I believe your answer is correct. Since I didn’t really need the subdomain, though, I finally decided to go with the simpler solution of creating a resource group. My original purpose in this whole project was to restrict access so some admin pages I’m creating, which can be accomplished without the use of a separate context. Nonetheless, I am curious enough to want to find out why I couldn’t get it to work. It’s always possible I’ll need to revisit the issue at a later date, or have some as-yet-unforeseen use for this kind of structure.
              • 9102 ☆ A M B ☆
              • 318 Posts
              does your browser display the URL as yourdomain.com/yoursubdomain

              No, and that’s definitely your problem, I didn’t realize that. It ought to be doing a rewrite, not a redirect, so that the URL displayed in your browser is subdomain.domain.com, that’s the whole point of a subdomain.

              I’d contact your webhost. Try to avoid talking about MODx and just get them to fix the rewrite so that your subdomain resolves correctly.
                • 13643
                • 44 Posts
                Well, it’s always nice to clarify the problem, even if the solution still eludes me. I contacted the web host as you suggested, and they insisted that cPanel couldn’t be the problem. We tried disabling .htaccess, and that didn’t help either. I don’t know if there’s some way MODx could be causing this behavior or not, but I can’t spend too much time right now trying to figure it out, since it’s no longer important to my current project. Anyway, thanks for all your help. I may come back to this issue some time in the future.