We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7231
    • 4,205 Posts
    I have a client who has 3 domains all pointing to the same server (actually one domain with three tlds...com, .org and .net). Currently you can access the site fine with any of the 3 domains no problem. However I was wondering if it is possible to force it to use only on of the domains.

    What I mean is currently if you access the site with either mydomain.com or mydomain.org both work but the address in the browser will stick to the domain that was uses to reach the site. I was wondering it it is possible to force the browser to always use only one of the domains. So it the visitor reaches the site with the .org domain it shows up as the .com.

    I could setup redirect pages for each domain but figured there may be an easier solution with htaccess.

    Hope this makes sense rolleyes
      [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

      Something is happening here, but you don't know what it is.
      Do you, Mr. Jones? - [bob dylan]
      • 5727
      • 160 Posts
      It is possible using 3 lines, modified from those already found in the default ht.access file that comes with MODx.

      # Rewrite domain.org-> domain.com
      RewriteCond %{HTTP_HOST} .
      RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
      RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
      


      Basically, what this does it, check if the domain is not www.domain.com, change it to www.domain.com
      This will also force people going to domain.com (without the www) to www.domain.com

      Hope this works for you.
        Olivier Deland
        Montreal, Canada - Web Developer
        • 6726
        • 7,075 Posts
        The 3 lines in the default .htaccess are meant for the SEO Strict URLs plugin and unless I am wrong, those only prevent duplicates between www.domain.tld and domain.tld

        I you need a .org and .net redirected to the .com, simply place a .htaccess with a 301 redirect on the ftp folder for those domains. I have this up and running in each domain to be redirected to the main domain with this in the .htaccess :

        [tt]RedirectPermanent / http://www.domain.tld/[/tt]

        @conseilweb: Are you sure those rules do not conflict with the MODx / SEO Strict URLs install rules if you set them also on the other (secondary) domains ?
          .: COO - Commerce Guys - Community Driven Innovation :.


          MODx est l'outil id
          • 33372
          • 1,611 Posts
          Or of course you can do the opposite (redirect www.anyofyourdomains.com to theonedomainyouwant.com), which is starting to become popular:

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


          As ConseilsWeb mentioned, these lines are already in your MODx .htaccess file; they’ve just been commented out. You just need to change the placeholder domain names to yours and remove the #’s at the beginning of each line. I also strongly recommend the SEO Strict URLs plugin if you’re not already using that.

          @davidm: Take another look at those rules. They redirect any domain that is not (!) the one you want to the one you want. They will work with or without the SEO Strict URLs plugin.
            "Things are not what they appear to be; nor are they otherwise." - Buddha

            "Well, gee, Buddha - that wasn't very helpful..." - ZAP

            Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
            • 7231
            • 4,205 Posts
            Worked like a charm. This was too easy...but that is not a surprise. Thanks grin

            As for SEO Strict URLs plugin, I am not using it never have so far. I am not too sure what the benefits are (my SEO skills are entry level).

            This plugin uses 301 redirects to forward users and search engines alike to a single URL based on plugin and FURL configuration. In addition to redirecting, the plugin can also (optionally) rewrite document links/URIs.
            I understand the method but not the principal. It seems that there are quite a few scenarios where you could access a doc in at least two methods: ../dir/ is the same as ../dir/index.html or ../dir/default.html (depending on your server).
              [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

              Something is happening here, but you don't know what it is.
              Do you, Mr. Jones? - [bob dylan]
              • 33372
              • 1,611 Posts
              Quote from: dev_cw at Mar 16, 2008, 02:06 PM

              I understand the method but not the principal. It seems that there are quite a few scenarios where you could access a doc in at least two methods: ../dir/ is the same as ../dir/index.html or ../dir/default.html (depending on your server).
              Exactly. The plugin redirects all URLs that point to identical pages to the one preferred URL. The idea is that you want to make sure that search engine indexes to all pages in your site are concentrated in unique URLs. That way they don’t store some of your ranking credit at www.mydomain.com/index.html and some at www.mydomain.com/ and yet more at www.mydomain.com/index.php?id=1. They’re the same page, and the plugin makes sure that you never show more than one URL for it. It also 301 redirects requests for non-preferred URLs to the preferred ones.
                "Things are not what they appear to be; nor are they otherwise." - Buddha

                "Well, gee, Buddha - that wasn't very helpful..." - ZAP

                Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
                • 7231
                • 4,205 Posts
                That way you don’t get half of your ranking credit at www.mydomain.com/index.html and the other half at www.mydomain.com/.
                OK, that makes sense. I have seen this ill effect when monitoring page rankings and seeing one result for www.domain.tld and another for domain.tld. Thanks for clearing this up grin
                  [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                  Something is happening here, but you don't know what it is.
                  Do you, Mr. Jones? - [bob dylan]
                  • 6726
                  • 7,075 Posts
                  Quote from: ZAP at Mar 16, 2008, 01:39 PM
                  @davidm: Take another look at those rules. They redirect any domain that is not (!) the one you want to the one you want. They will work with or without the SEO Strict URLs plugin.

                  Ok thanks for clearing that up !
                  This is really cool cool
                    .: COO - Commerce Guys - Community Driven Innovation :.


                    MODx est l'outil id