We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18367
    • 834 Posts
    I've set up a sub domain to store images etc, however the default recommended htaccess code for FURLs from modx (ie the one that comes with the install) keeps rewriting the subdomain back to the main domain.

    Anyone know how to get around this?

    Thanks

    That is, without breaking FURLs in the process.

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

    [ed. note: markg last edited this post 9 years, 10 months ago.]
      Content Creator and Copywriter
    • You can exclude subdirectories and subdomains from the rewrite rules.
      RewriteCond %{HTTP_HOST} !^subdomain\.domain\.com
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 18367
        • 834 Posts
        Susan,

        this stuff always confuses me.

        If your example is an exclusion
        RewriteCond %{HTTP_HOST} !^subdomain\.domain\.com

        It looks similar to the default code for an inclusion
        RewriteCond %{HTTP_HOST} !^example-domain-please-change\.com [NC]

        IE why are the negate marks (!) even in the default htaccess code?

        I'm just asking for my own understanding.

        I used to write it like this
        RewriteCond %{HTTP_HOST} ^example-domain-please-change\.com [NC]

        and that used to work perfectly for years.


        Thanks
          Content Creator and Copywriter
        • discuss.answer
          The ! means NOT. The ^ means STARTS WITH. Always. The escape (\) is needed in the RewriteCond line to use the . as part of the text, not a regular expression instruction.
          RewriteCond %{HTTP_HOST} !^subdomain\.domain\.com

          If it DOES NOT start with subdomain.domain.com, do the following.

          RewriteCond %{HTTP_HOST} !^example-domain-please-change\.com [NC]

          Again, if DOES NOT start with example-domain-please-change\.com (upper or lower case), do the following.

          RewriteCond %{HTTP_HOST} ^example-domain-please-change\.com [NC]

          If it starts with example-domain-please-change.com (upper or lower case), do the following.

          You are referring to lines like this:
          #RewriteCond %{HTTP_HOST} !^example-domain-please-change\.com [NC]
          #RewriteRule (.*) http://example-domain-please-change.com/$1 [R=301,L]
          

          They work together. It means "if it doesn't start with domain.com, the rewrite it to just be domain.com, use a 301 redirect, and that's the last line for this particular rule". So this will rewrite www.domain.com, dev.domain.com, anything.domain.com to just domain.com.
          #RewriteCond %{HTTP_HOST} !^www\.example-domain-please-change\.com [NC]
          #RewriteRule (.*) http://www.example-domain-please-change.com/$1 [R=301,L]
          

          This does just the opposite, in case you want your URLs to always be www.domain.com. If you were using one of those rules, and wanted to use files.domain.com, you would simply add another RewriteCond line to tell it not to apply the rule for your files subdomain:
          #RewriteCond %{HTTP_HOST} !^files\.example-domain-please-change\.com [NC]


            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 18367
            • 834 Posts
            Thanks,

            I'm part way there.

            sub domains working

            non www working, sort of but I get
            public_html/
            on the end of my url.

            Also how do I get index to rewrite to the main domain.

            Full code below.
            RewriteEngine On
            RewriteBase /
            
            RewriteCond %{HTTP_HOST} ^domain\.com\.au [NC]
            RewriteRule ^(.*)$ http://www.domain.com.au/$1 [R=301,L]
            
            RewriteCond %{HTTP_HOST} ^www\.domain\.com\.au/index [NC]
            RewriteRule ^(.*)$ http://www.domain.com.au/$1 [R=301,L]
            RewriteCond %{HTTP_HOST} !^files\.domain\.com\.au [NC]
            
            
            # The Friendly URLs part
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
              Content Creator and Copywriter
            • You can't have a RewriteCond after a RewriteRule. The RewriteRule is controlled by the RewriteCond. Especially since the L modifier indicates the end of that Rule.
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 18367
                • 834 Posts
                Here's what I ended up with.

                It all works.

                RewriteEngine On
                RewriteBase /
                
                
                RewriteCond %{HTTP_HOST} ^domain\.com\.au [NC]
                RewriteCond %{HTTP_HOST} !^files\.domain\.com\.au [NC]
                RewriteRule ^(.*)$ http://www.domain.com.au/$1 [R=301,L]
                
                RewriteCond %{HTTP_HOST} ^www\.domain\.com\.au/index [NC]
                RewriteRule ^(.*)$ http://www.domain.com.au/$1 [R=301,L]
                
                RewriteCond %{THE_REQUEST} ^.*/index
                RewriteRule ^(.*)index$ http://www.domain.com.au/$1 [R=301,L]
                
                # The Friendly URLs part
                RewriteCond %{REQUEST_FILENAME} !-f
                RewriteCond %{REQUEST_FILENAME} !-d
                RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
                  Content Creator and Copywriter