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. Technical SEO Issues
    4. Www to non www

    Www to non www

    Technical SEO Issues
    9 5 543
    • 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.
    • seoug_2005
      seoug_2005 last edited by

      Hi,

      Is this the correct code for redirecting www to non www version on Apache server

      RewriteEngine

      OnRewriteCond %{HTTP_HOST} ^www.example.com

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

      Thanks

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

        You've just missed the "on" at the end of the first line and have it at the start of the 2nd I think (not sure if that matters). So,

        RewriteEngine On

        And then take the www off the second line. So,

        RewriteCond %{HTTP_HOST} ^example.com

        seoug_2005 1 Reply Last reply Reply Quote 1
        • seoug_2005
          seoug_2005 @SteveOllington last edited by

          Is this correct

          RewriteEngine on

          RewriteCond %{HTTP_HOST} ^example.com

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

          What does $1 mean ?

          AlanMosley DanHill SteveOllington 4 Replies Last reply Reply Quote 0
          • AlanMosley
            AlanMosley @seoug_2005 last edited by

            Look i work on windows servers so i dont use htaccess, so i am no expert with htaccess, but I do know regex pretty well,

            I think you have it wrong in 2 ways.

            1. you are directed from non www. to www the wrong way.

            Also the rewrite condition is a RegEx, it needs to be escaped

            so i think you should have

            RewriteCond %{HTTP_HOST} ^www.example.com

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

            This is all so much easier on windows servers

            1 Reply Last reply Reply Quote 0
            • DanHill
              DanHill @seoug_2005 last edited by

              The $1 basically copies everything that precedes it ( http://www.example.com/ )

              This is so that for each URL it rewrites you don't have to give it the above URL over and over again.

              Hope this makes sense  🙂

              **'**If the matched regex contains groups in parentheses, $1..$9 in the replacement refer to the captured text in the
              matching group "$1" meaning the first group, "$2" the second, and so on.'

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

                RewriteEngine On

                RewriteBase /

                RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC]

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

                Put that in your .htaccess within your root web directory (typically public_html), and you should be good.

                Make sure you save your .htaccess file properly (save as "All files" and not "as text file" so the .txt doesn't get appended to it.

                seoug_2005 1 Reply Last reply Reply Quote 1
                • SteveOllington
                  SteveOllington @seoug_2005 last edited by

                  Hehe I was going non www to www wasn't I, I should learn to read properly, well spotted!

                  1 Reply Last reply Reply Quote 0
                  • SteveOllington
                    SteveOllington @seoug_2005 last edited by

                    Double post... I only clicked one though so... random!

                    Also, yukky windows servers 😜 hehe

                    1 Reply Last reply Reply Quote 0
                    • seoug_2005
                      seoug_2005 @THB last edited by

                      Many Thanks to all of you for your clarifications .

                      1 Reply Last reply Reply Quote 0
                      • 1 / 1
                      • First post
                        Last post
                      • Worth redirecting non-www to www due to higher page authority with www?
                        GastonRiera
                        GastonRiera
                        0
                        4
                        276

                      • SSL, www issue. Should we buy WWW license or just add redirect from www to non-www site?
                        Ryan_V
                        Ryan_V
                        0
                        8
                        141

                      • WWW to Non-WWW = Less Indexing?
                        BradyDCallahan
                        BradyDCallahan
                        0
                        3
                        178

                      • Duplicate Content Issue WWW and Non WWW
                        TheeDigital
                        TheeDigital
                        1
                        3
                        1.6k

                      • Which to redirect to, www or non-www?
                        Perfect007
                        Perfect007
                        0
                        3
                        169

                      • Redirecting non-www to www
                        Christy-Correll
                        Christy-Correll
                        0
                        6
                        466

                      • Difference between www and non-www site
                        Cyrus-Shepard
                        Cyrus-Shepard
                        0
                        6
                        7.8k

                      • Www vs non-www
                        kylesuss
                        kylesuss
                        0
                        6
                        808

                      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