We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 41149
    • 43 Posts
    Hello, I have installed MODx Revolution 2.2 under a Directory, and am curious as to how I can manage to have proper redirection. For example:

    #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]


    I want:
    mydomain.com to always redirect to www.mydomain.com regardless of the URL/URI entered in after the root.

    I have MODx installed under /blog so I need:
    mydomain.com/blog to always redirect to www.mydomain.com/blog regardless of the URL/URI following /blog.

    I am running Apache.
    Thank you so much for your help!
      The web is our sandbox, so let's develop a castle.
      • 30912
      • 463 Posts
      try this:

      Options +FollowSymlinks
      RewriteEngine On
      
      #this is your base directory
      RewriteBase /blog/
      
      
      #enter your domain here
      RewriteCond %{HTTP_HOST} .
      RewriteCond %{HTTP_HOST} !^www\.mydomain\.com [NC]
      RewriteRule (.*) h ttp://www.mydomain.com/$1 [R=301,L]
      
      
      


      (dont forget to remove the space in the http)
        • 41149
        • 43 Posts
        Quote from: Tyreal2012 at Apr 11, 2012, 03:44 AM
        try this:

        Options +FollowSymlinks
        RewriteEngine On
        
        #this is your base directory
        RewriteBase /blog/
        
        
        #enter your domain here
        RewriteCond %{HTTP_HOST} .
        RewriteCond %{HTTP_HOST} !^www\.mydomain\.com [NC]
        RewriteRule (.*) h ttp://www.mydomain.com/$1 [R=301,L]
        
        
        


        (dont forget to remove the space in the http)

        This helps, but when I type in:

        mydomain.com/blog

        It redirects to www.mydomain.com

        And when I put in www.mydomain.com/blog

        It redirects to www.mydomain.com/blog

        When I don't use the www. it redirects to the root hence www.mydomain.com when I do use the www.mydomain.com/blog it redirects to www.mydomain.com/blog

        Any ideas?
        Thank you so much by the way!
          The web is our sandbox, so let's develop a castle.
          • 30912
          • 463 Posts
          im approaching my limits of knowledgere here but try:

          RewriteCond %{HTTP_HOST} !^www\.mydomain\.com [NC]
          RewriteRule (.*) h ttp://www.mydomain.com/blog/$1 [R=301,L]


          itll eithe rfix it or break it (my guess is the latter laugh)
            • 18373 ☆ A M B ☆
            • 3,141 Posts
            Try putting
            #enter your domain here
            RewriteCond %{HTTP_HOST} .
            RewriteCond %{HTTP_HOST} !^www\.mydomain\.com [NC]
            RewriteRule (.*) h ttp://www.mydomain.com/$1 [R=301,L]

            in a .htaccess file in the root of the server (mydomain.com/.htaccess)

            Then rename the ht.access file shipped with MODX to .htaccess, and make sure to change the RewriteBase to /blog/, and theoretically you should then be ready to go.
              Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

              Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.