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
                    • 301 redirect hops from non-https and www
                      ThompsonPaul
                      ThompsonPaul
                      0
                      3
                      335

                    • Best practice to 301 NON-WWW pages?
                      mememax
                      mememax
                      0
                      4
                      91

                    • I've submitted a disavow file in my www version account, should I submit one in my non-www version account as well?
                      MonicaOConnor
                      MonicaOConnor
                      0
                      3
                      108

                    • Our client's web property recently switched over to secure pages (https) however there non secure pages (http) are still being indexed in Google. Should we request in GWMT to have the non secure pages deindexed?
                      N1ghteyes
                      N1ghteyes
                      0
                      3
                      128

                    • Do I need to set Preferred domain when the non-www redirects to www version?
                      Ideas-Money-Art
                      Ideas-Money-Art
                      0
                      4
                      1.8k

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

                    • How to redirect www vs. non-www in IIS
                      AlanMosley
                      AlanMosley
                      0
                      5
                      2.2k

                    • Redirect of just one internal page
                      kolio_kolev
                      kolio_kolev
                      0
                      3
                      918

                    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