We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40088
    • 708 Posts
    I have MODX 2.3 running fine in the site root, e.g., http://parent.domain. I recently added a separate and unrelated (non-MODX) addon domain, e.g., http://addon.domain to the parent hosting account. The problem is that when I visit the addon url it redirects to the parent site.

    I know it's a MODX .htaccess thing but I'm unsure how to fix the redirect issue without messing up the (parent) MODX site.

    This question has been answered by AMDbuilder. See the first response.

      Todd
      • 1343 ☆ A M B ☆
      • 2,213 Posts
      If you are using any of these lines uncommented they will cause the behavior you're describing. Simply remove them and/or switch to generic rewrites.

      Bad Redirects:

      # Rewrite www.domain.com -> domain.com -- used with SEO Strict URLs plugin
      #RewriteCond %{HTTP_HOST} .
      #RewriteCond %{HTTP_HOST} !^example-domain-please-change\.com [NC]
      #RewriteRule (.*) http://example-domain-please-change.com/$1 [R=301,L]
      #
      # or for the opposite domain.com -> www.domain.com use the following
      # DO NOT USE BOTH
      #
      #RewriteCond %{HTTP_HOST} .
      #RewriteCond %{HTTP_HOST} !^www\.example-domain-please-change\.com [NC]
      #RewriteRule (.*) http://www.example-domain-please-change.com/$1 [R=301,L]
      
      
      
      # Rewrite secure requests properly to prevent SSL cert warnings, e.g. prevent 
      # https://www.domain.com when your cert only allows https://secure.domain.com
      #RewriteCond %{SERVER_PORT} !^443
      #RewriteRule (.*) https://example-domain-please-change.com/$1 [R=301,L]
      


      Super Basic Force WWW (untested)

      RewriteCond %{HTTP_HOST} !^www\.
      RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
      


      Super Basic Force NO - WWW (untested)

      RewriteCond %{HTTP_HOST} www\.
      RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
      


      That should get you headed in the right direction.
        Patrick | Server Wrangler
        About Me: Website | Tweets |  MODX Hosting
        • 40088
        • 708 Posts
        Hi AMDbuilder,

        Thank you. It seems to be working now, although in a slightly different manner than you suggested. Hopefully this approach doesn't cause other problems.

        In the parent account (/public_html/) I left the MODX redirect uncommented:
        Rewrite www.domain.com -> domain.com -- used with SEO Strict URLs plugin
        RewriteCond %{HTTP_HOST} .
        RewriteCond %{HTTP_HOST} !^example-domain-please-change\.com [NC]
        RewriteRule (.*) http://example-domain-please-change.com/$1 [R=301,L]
        


        And in the addon directory (/public_html/my-addon-domain.us/) I added an .htaccess with your suggestion:

        Super Basic Force NO - WWW (untested)
        RewriteCond %{HTTP_HOST} www\.
        RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
        
          Todd
        • discuss.answer
          • 1343 ☆ A M B ☆
          • 2,213 Posts
          Actually, you would want to replace the lines in the main .htaccess with those lines from the addon domain. The goal is not to force a specific domain, which is what the default .htaccess code does. The code I provided focus strictly on forcing or removing the www based on the domain visited.

          Technically, you could still visit the main domain.com/addondomain.com as nothing is forced - there are ways to address that as well. Generally, I recommend making your life easy and putting the addon domains above the public_html directory if your host allows it. The .htaccess doesn't conflict that way so you can force the domains.
            Patrick | Server Wrangler
            About Me: Website | Tweets |  MODX Hosting
            • 40088
            • 708 Posts
            Curious. I tried your suggestion the first time around and it didn’t work for some reason. Now it does. Perhaps I made a mistake.

            Thank you!
              Todd
              • 1343 ☆ A M B ☆
              • 2,213 Posts
              Glad to hear you got things working!
                Patrick | Server Wrangler
                About Me: Website | Tweets |  MODX Hosting