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. Intermediate & Advanced SEO
    4. Redirecting non-www pages to www ones

    Redirecting non-www pages to www ones

    Intermediate & Advanced SEO
    8 4 798
    • 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.
    • romanbond
      romanbond last edited by

      Hello:
      I'm trying to consolidate all the link juice and see that some of my pages are linked to by using both www.mysite.com/whatever.html and mysite.com/whatever.html.
      Is there a safe re-write rule that not just redirects non-www(s) to www(s), but designates the redirect as 301, so link juice will be transfered as well.

      If not RewriteRule, are there any other ways to accoplishe this?

      And the last question: can this be solved by simply setting Preffered domain in google webmaster tools to display www URL?

      Any help will be appreciated.

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

        I would set the preferred domain in google webmaster tools to www. and do 301 redirects to www.

        Webmaster tools will only effect how the link appears in search results, but not other external sources. Use the 301 redirect for that.

        An example of one is

        RewriteEngine On

        non-WWW to WWW redirect

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

        Hope it helps,

        Adam

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

          This can be done within .htaccess. The code below should work -

          RewriteEngine On
          RewriteCond %{HTTP_HOST} ^example.com
          RewriteRule (.*) http://www.example.com/$1 [R=301,L]

          The link juice will be transferred since it is a 301 redirect. And you can set your preferred domain within GWT but ideally you still want to use 301 redirects as well.

          1 Reply Last reply Reply Quote 1
          • romanbond
            romanbond last edited by

            what's the difference between:
            RewriteRule (.) http://www.example.com/$1 [R=301,L]  and
            RewriteRule ^(.
            )$ http://www.%{HTTP_HOST}/$1 [R=301,L]

            any significance in using the root domain URL there instead of just www.%

            NaescentAdam 1 Reply Last reply Reply Quote 0
            • NaescentAdam
              NaescentAdam @romanbond last edited by

              The first one defines your url exactly so you can replace example.com with your own. The second one I used takes the http host variable from the header and fills it in for you.

              In other words when a request is made to the site apache looks at the domain name and fills it in.

              I use the second because it means there are large portions of my .htaccess file I can just copy and paste between multiple sites. As always there is more than one answer!!

              Adam

              NaescentAdam romanbond bilalyaqoob 3 Replies Last reply Reply Quote 1
              • NaescentAdam
                NaescentAdam @NaescentAdam last edited by

                also I use www. because it looks nicer, but its 6 of one and half a dozen of another....

                1 Reply Last reply Reply Quote 0
                • romanbond
                  romanbond @NaescentAdam last edited by

                  thank you, that's what I need too, something I copy across multiple sites without having to change the domain URL every time. Appreciate your help.

                  1 Reply Last reply Reply Quote 0
                  • bilalyaqoob
                    bilalyaqoob @NaescentAdam last edited by

                    I also need to redirect my category pages from non-www to www. There is no option in Google web master tools for category pages, can you share with me exactly the code for my category page?????

                    1 Reply Last reply Reply Quote 0
                    • 1 / 1
                    • First post
                      Last post
                    • We are redirecting http and non www versions of our website. Should all versions http (non www version and www version) and https (non www version) should just have 1 redirect to the https www version?
                      BlueprintMarketing
                      BlueprintMarketing
                      0
                      8
                      437

                    • Would You Redirect a Page if the Parent Page was Redirected?
                      Nozzle
                      Nozzle
                      0
                      4
                      92

                    • Www vs Non-www version - should we still redirect?
                      Martijn_Scheijbeler
                      Martijn_Scheijbeler
                      0
                      2
                      71

                    • 301 redirect hops from non-https and www
                      ThompsonPaul
                      ThompsonPaul
                      0
                      3
                      335

                    • Any downsides of (permanent)redirecting 404 pages to more generic pages(category page)
                      MatthewBarby
                      MatthewBarby
                      0
                      2
                      133

                    • Redirect non www. domain to WWW. domain for established website?
                      SEO5Team
                      SEO5Team
                      0
                      4
                      281

                    • End of March we migrated our site over to HubSpot. We went from page 3 on Google to non existent. Still found on page 2 of Yahoo and Bing. Beyond frustrated...HELP PLEASE "www.vortexpartswashers.com"
                      Jben
                      Jben
                      0
                      4
                      484

                    • WWW vs Non-WWW/Moving a site to a new CMS/Redirect all of the previous URLs
                      KeriMorgret
                      KeriMorgret
                      0
                      5
                      934

                    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