The Moz Q&A Forum

    • Forum
    • Questions
    • My Q&A
    • Users
    • Ask the Community

    Welcome to the Q&A Forum

    Browse the forum for helpful insights and fresh discussions about all things SEO.

    1. SEO and Digital Marketing Q&A Forum
    2. Categories
    3. On-Page / Site Optimization
    4. Redirect sub domain to domain in .htaccessU

    Redirect sub domain to domain in .htaccessU

    On-Page / Site Optimization
    4 2 496
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as question
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • rasmusbang
      rasmusbang last edited by

      Hi all,

      (Total newbie with fourth post of the last 7 days askin' for help!...sorry!)

      I've discovered that we have a lot of URLs indexed with for example:

      http://test.betxpert.com/some-odd-url

      This gives me duplicate content in the search engines. I have searched the web and i can not find a solution fore redirecting http://test.betxpert.com/some-odd-url to http://www.betxpert.com/some-odd-url. Can anyone help me what to write in the .htaccess file?

      Best regards,

      Rasmus

      1 Reply Last reply Reply Quote 0
      • KeriMorgret
        KeriMorgret last edited by

        The greater question is..do you even want the test subdomain indexed? If that's there for you testing stuff in development, then redirecting is going to mean that you can't test anything.

        If that subdomain shouldn't be in the SERPs at all, what about putting a robots.txt on it to exclude it from being indexed, then go verify the subdomain in Google Webmaster Tools where you can then remove the entire subdomain from the index?

        rasmusbang 1 Reply Last reply Reply Quote 0
        • rasmusbang
          rasmusbang @KeriMorgret last edited by

          Actually, I don't use the subdomain. For some reason we have it on the server. Along with odds.betxpert.com. Again we do not use them.

          What would be the best solution?

          a) Redirect 301 from the sub to the main domain

          b) Simply tell Google through the robots.txt that they are not to index the pages for the subdomains.

          As it is now the sub adresses are competitors to the main pages? So I need to lose them?

          What would happen if i simply remove the subdomains from the server such that google gets errors? That would be a problem right?

          1 Reply Last reply Reply Quote 0
          • rasmusbang
            rasmusbang last edited by

            I managed to fix this, just wanted to post the solution.

            For redirecting traffic without "www." to "www.":

            RewriteCond %{HTTP_HOST} ^domain.com [NC]

            RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]

            For redirecting "test." pages to "www." pages:

            RewriteCond %{HTTP_HOST} test.domain.com [NC]

            RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]

            Add these lines to .htaccess and all is well 🙂

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            • Naked domain redirection info
              Mustansar
              Mustansar
              0
              3
              392

            • Can Robots.txt on Root Domain override a Robots.txt on a Sub Domain?
              RyanPurkey
              RyanPurkey
              0
              3
              522

            • Help an SEO-DUMMY : ) Established hyphenated domain...redirect?!...new domain?!
              Andy.Drinkwater
              Andy.Drinkwater
              0
              3
              352

            • Campaign set up as sub domain
              PhilSmith23
              PhilSmith23
              0
              4
              164

            • Redirecting a Parked Domain
              ThompsonPaul
              ThompsonPaul
              0
              3
              352

            • Can I exclude sub-domains from the crawl diagnostics?
              JustinTaylor88
              JustinTaylor88
              0
              2
              443

            • New Domain or Sub Domain for Mobile content
              theshortstack
              theshortstack
              0
              4
              518

            • Redirecting to a keyword-rich domain URL
              G-Force
              G-Force
              0
              6
              1.2k

            Get started with Moz Pro!

            Unlock the power of advanced SEO tools and data-driven insights.

            Start my free trial
            Products
            • Moz Pro
            • Moz Local
            • Moz API
            • Moz Data
            • STAT
            • Product Updates
            Moz Solutions
            • SMB Solutions
            • Agency Solutions
            • Enterprise Solutions
            • Digital Marketers
            Free SEO Tools
            • Domain Authority Checker
            • Link Explorer
            • Keyword Explorer
            • Competitive Research
            • Brand Authority Checker
            • Local Citation Checker
            • MozBar Extension
            • MozCast
            Resources
            • Blog
            • SEO Learning Center
            • Help Hub
            • Beginner's Guide to SEO
            • How-to Guides
            • Moz Academy
            • API Docs
            About Moz
            • About
            • Team
            • Careers
            • Contact
            Why Moz
            • Case Studies
            • Testimonials
            Get Involved
            • Become an Affiliate
            • MozCon
            • Webinars
            • Practical Marketer Series
            • MozPod
            Connect with us

            Contact the Help team

            Join our newsletter
            Moz logo
            © 2021 - 2026 SEOMoz, Inc., a Ziff Davis company. All rights reserved. Moz is a registered trademark of SEOMoz, Inc.
            • Accessibility
            • Terms of Use
            • Privacy