We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36926
    • 701 Posts
    Hi,

    I have a couple of domains mapped to one main domain. Is there anything i can actually add say in the .htaccess file that will redirect a domain to the primary domain?

    Thanks

    Ben
      • 16702 ☆ A M B ☆
      • 536 Posts
      #Options +FollowSymLinks
      RewriteEngine on
      RewriteCond %{HTTP_HOST} ^www.olddomain.com$[OR]
      RewriteCond %{HTTP_HOST} ^olddomain.com$
      RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]
        palma non sine pulvere
        • 36926
        • 701 Posts
        Quote from: Kristalin at Apr 15, 2010, 08:45 PM

        #Options +FollowSymLinks
        RewriteEngine on
        RewriteCond %{HTTP_HOST} ^www.olddomain.com$[OR]
        RewriteCond %{HTTP_HOST} ^olddomain.com$
        RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]

        Thanks for this Kristalin, unfortunatly I can’t seem to get this to work. I’m using the .htaccess file that’s in the root of the modx instal. Apart from changing the domains to the corrects ones, is there anything else I need to do.
          • 36926
          • 701 Posts

          Quote from: Kristalin at Apr 15, 2010, 08:45 PM

          #Options +FollowSymLinks
          RewriteEngine on
          RewriteCond %{HTTP_HOST} ^www.olddomain.com$[OR]
          RewriteCond %{HTTP_HOST} ^olddomain.com$
          RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]

          Ok after a bit more reading up on .htaccess and playing about about I’ve managed to get the following to work. Thanks Kristalin for putting me on the right track!

          #Options +FollowSymLinks
          RewriteEngine on
          RewriteCond %{HTTP_HOST} ^www.olddomain.com$ [OR]
          RewriteCond %{HTTP_HOST} ^olddomain.com$
          RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

          I’ve added a space before the [OR] and also changed the RewriteRule slightly. Would someone be able to explain what the (.*) is actually doing, and also what the $ sign after the olddomain.com does and the ^ before does?
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            Those are part of the "regular expressions" that specify which gets changed to what. A good explanation here: http://corz.org/serv/tricks/htaccess2.php

            ^ Start of line anchor
            $ End of line anchor

            An anchor explicitly states that the character right next to it MUST
            be either the very first character ("^"), or the very last character ("$")
            of the URI string to match against the pattern, e.g..

            ^foo(.*) matches foo and foobar but not eggfoo
            (.*)l$ matches fool and cool, but not foo
              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
              • 36926
              • 701 Posts
              Quote from: sottwell at Apr 19, 2010, 09:19 AM

              Those are part of the "regular expressions" that specify which gets changed to what. A good explanation here: http://corz.org/serv/tricks/htaccess2.php

              ^ Start of line anchor
              $ End of line anchor

              An anchor explicitly states that the character right next to it MUST
              be either the very first character ("^"), or the very last character ("$")
              of the URI string to match against the pattern, e.g..

              ^foo(.*) matches foo and foobar but not eggfoo
              (.*)l$ matches fool and cool, but not foo

              Thanks sottwell, that was actually one of the articles i’d read and was very helpful. But wasn’t 100% sure on the (.*) and $. But what you said makes perfect sense, thanks for clearing that up as I hate not know why and how a particular thing is doing something.

              Ben